Pregunta

What are my options when it comes to the following scenario:

  1. (existing) admin user creates a newUser via my web app
  2. newUser authenticates via FirebaseSimpleLogin Email/Password
  3. how do I associate the user data returned via the auth object to the newUser data stored at /users/{{newUserId}}?

Right now I'm thinking the simplest way is to use the user's email as the unique key, like so:

function createUser(newUserInfo){
    firebaseRef.$child('users/' + customerUserInfo.email).$set(newUserInfo);
}
function firebaseSimpleLoginSuccess(auth){
    var userInfo = firebaseRef.$child('users/' + auth.user.email);
}

But this isn't as scalable as I'd like, given that the user is then disallowed from changing their email, or associating multiple emails with their account.

Is there another way?

EDIT: realized after the fact that firebase array keys can't contain special characters, but the principle still applies: clean the email (e.g. user@gmail.com --> user-gmail-com), then use it as a key.

¿Fue útil?

Solución

Per https://www.firebase.com/docs/security/simple-login-email-password.html, the auth token payload after authenticating includes a unique numeric id (id) and an id that includes that numeric id but is guaranteed to be unique across Firebase Simple Login providers (uid). Storing the user data using one of these two ids will allow you to be able to handle changes to the user email (coming soon to Simple Login) or manually link multiple account credentials without any gnarly escaping of email addresses.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top