2
votes

Currently, I'm working with a firebase application that only uses the Google auth provider. There is a single sign-in flow for new and returning users that calls firebase.auth().signInWithPopup() to authenticate the user.

I want to populate an object on the firebase database that stores each new user's UUID and information about them. Ideally, I'd like to generate this information server side and not allow write access to the object from the client.

How can I best tell when a new user has signed up? I am passing the user's token to the server as a cookie to be authenticated with each request to make sure they're signed in and authorized. I could check the UUID of each request to see if it's already in the users object, but this seems hugely wasteful as the majority of requests will not be from new users.

1
You can use firebase functions. They provide a trigger on user sign up: firebase.google.com/docs/functions/auth-events - bojeil
@bojeil Thanks I think this is what I'll end up having to do. Ideally I'd like to keep all my application logic in the same place, but I think I might need to make this concession. - Philip Hickey

1 Answers

0
votes

modify rule of real time database:

 "rules": {
    "Users":{
      "$uid":{
          ".read": "auth.uid == $uid",
           ".write": "auth.uid == $uid"
}
}
}