WIP: Feat/user channel create delete#68
Conversation
oskarrough
left a comment
There was a problem hiding this comment.
So many things! Really cool. Still didn't get to test it, but found a few things to comment on anyway.
All of this also assumes the R4 frontend is updated, so it doesn't try to do everything twice?
| // write: only a user with no channel can write a new one to himself | ||
| ".write": "auth != null && (root.child('users').child(auth.uid).child('channels').child($channelID).exists() || (!data.exists() && !root.child('users').child(auth.uid).child('channels').exists()))", | ||
| ".validate": "newData.hasChildren(['slug', 'title', 'created']) || !newData.exists()", | ||
| ".validate": "newData.hasChildren(['title']) || !newData.exists()", |
There was a problem hiding this comment.
I believe slug was removed because it's now generated in the backend, but what about created?
There was a problem hiding this comment.
We should generate it in the Backend as well. My mistake!
| // create new /users/:newUser | ||
| let userRef = admin.database().ref(`/users/${userUid}`) | ||
| userRef.set({ | ||
| settings: userSettingsId, |
There was a problem hiding this comment.
shouldn't createUserSetting be part of this method? So you don't have to call both. Also, if you don't have a userSetting, how can you create a user?
There was a problem hiding this comment.
- usersettings = await createUserSettings(userId) https://github.com/internet4000/radio4000-api/pull/68/files#diff-1cca320b5f907e0ee8b85ce1f2984e4eR73
- user = await createUser(userSettings.key) https://github.com/internet4000/radio4000-api/pull/68/files#diff-1cca320b5f907e0ee8b85ce1f2984e4eR82
There was a problem hiding this comment.
the firebase.function.aut.onRegister = handleUserCreate
is splitted in functions that handle small part of this process
There was a problem hiding this comment.
Sorry I'm confused. So what's the steps to create a new user from a front-end perspective?
var userRef = await database.ref('/users').push()
userRef.set({someProperty: 'helloword'})
And then backend takes care of the usersetting?
| let userRef = admin.database().ref(`/users/${userUid}`) | ||
| return await userRef.once('value').then(dataSnapshot => { | ||
| return dataSnapshot.val() | ||
| }) |
There was a problem hiding this comment.
Stick to either await or then?
| let userRef = admin.database().ref(`/users/${userUid}`) | |
| return await userRef.once('value').then(dataSnapshot => { | |
| return dataSnapshot.val() | |
| }) | |
| let userRef = admin.database().ref(`/users/${userUid}`) | |
| let snapshot = await userRef.once('value') | |
| return snapshot.val() |
There was a problem hiding this comment.
yep, but here the second await is not needed, as everything happens sequentially in the then
| console.log('channels', channels) | ||
| if (!channels) { | ||
| return | ||
| } |
There was a problem hiding this comment.
Needs to delete the channels.
| when a channel is deleted | ||
| */ | ||
|
|
||
| const handleChannelDelete = async (change, context) => { |
There was a problem hiding this comment.
minor but move this method to the end of the file? So it reads create, update, delete.
| await userChannelRef.update({ | ||
| slug: slugify(title) | ||
| }) |
There was a problem hiding this comment.
inside R4 front-end we validate slug to make sure it's unique. Guess we need to do that here before updating?
There was a problem hiding this comment.
This is totally correct! Glad you are looking at the file!
| "staging": "radio4000-staging" | ||
| "staging": "radio4000-staging", | ||
| "dev": "radio4000-hugurp", | ||
| "default": "radio4000-hugurp" |
There was a problem hiding this comment.
is default used anywhere or can we remove?
|
|
||
| let updates = {} | ||
| Object.keys(followers).forEach(followerId => { | ||
| updates[`/channels/${followerId}/favoriteChannels/${channelId}`] = null |
There was a problem hiding this comment.
where does channelId come from?
| nvm install 10.10.0 // install node 10 | ||
| nvm use 10.10.0 // use node 10 | ||
| npm // install npm dependencies with yarn |
There was a problem hiding this comment.
Does it need 10.10.0 or just 10.x?
| nvm install 10.10.0 // install node 10 | |
| nvm use 10.10.0 // use node 10 | |
| npm // install npm dependencies with yarn | |
| nvm use 10 | |
| npm install |
| await userChannelRef.update({ | ||
| slug: slugify(title) | ||
| slug: slugify(title), | ||
| created: admin.database.ServerValue.TIMESTAMP, |
There was a problem hiding this comment.
so nice if we don't have to deal with timestamps in the frontend
Handle:
channel.slug = slugify(channel.title)channel.channelPublic.followers.forEach( delete favorites[channel]channel.slug = slugify(channel.slug || channel.title)No so easy to test functions locally, and deploy. So many google, gcloud, firebase login things, service accounts. Heavy to maintain and document, have to put CI/CD, but that as well. Having to go through the service accounts and api access interfaces, be sure that everything use the correct profiles, re-generate everything to rotate-keys...