0

I'm using Firebase in a node.js backend for authentication.
After authentication, the data retrieved by Firebase are like this :

{
  auth: {
    provider: 'password',
    uid: '1234'
  },
  expires: 1452072779,
  token:'token',
  uid: '4567',
  provider: 'password'
}

However I cannot get the username. Do you know if there is a way to get it ?

rocketer
  • 1,051
  • 3
  • 13
  • 40
  • i have not used it in a while but i think you looking for `authData.uid` - you can maybe find this useful? - https://www.firebase.com/docs/web/guide/user-auth.html – TrojanMorse Jan 05 '16 at 09:57
  • Not really, I would like to get the email because every user has an email address. – rocketer Jan 05 '16 at 09:59
  • are you using the custom Authentication provider and managing your own tokens or the Email & password authenticaton – TrojanMorse Jan 05 '16 at 10:00
  • On first login, user authenticates with email and password and stores locally a token. For every other requests, I use custom authentication by using the token. – rocketer Jan 05 '16 at 10:06
  • When using authentication using token you can't get the email from the authentication data. When using email and password for login this can. Myabe an idea to save the email in your database? – André Kool Jan 05 '16 at 10:15

2 Answers2

0

In Android API, there is such a method called getProviderData() and you can do the following getProviderData().getEmail() but it seems there is no such thing in Javascript API... Can someone confirm this ?

rocketer
  • 1,051
  • 3
  • 13
  • 40
  • In javascript you can get the email (when using email and password for login) using ref.getAuth().password.email. source: https://www.firebase.com/docs/web/guide/login/password.html – André Kool Jan 05 '16 at 10:18
  • Thanks, I was confused because I was testing with Facebook authentication and Facebook credentials don't show email address. – rocketer Jan 05 '16 at 10:42
0

Since you are using email and password with the first login and after that a token for login you can store the email of the user in your firebase itself so you can get it using the uid even when you login in with a token.

Take a look at https://www.firebase.com/docs/web/guide/user-auth.html#section-storing or How do I link each user to their data in Firebase? for an example.

Community
  • 1
  • 1
André Kool
  • 4,880
  • 12
  • 34
  • 44