Home > database >  Firebase Auth, in custom tokens what some-uid should be?
Firebase Auth, in custom tokens what some-uid should be?

Time:04-10

https://firebase.google.com/docs/auth/admin/create-custom-tokens

const uid = 'some-uid';

getAuth()
  .createCustomToken(uid)
  .then((customToken) => {
    // Send token back to client
  })
  .catch((error) => {
    console.log('Error creating custom token:', error);
  });

I don't know what to put in "some-uid" in this scenario. Maybe I should put in a unique id that has never been used. I plan to do other social sign in & up that firebase does not provide.


by the way, If implemented like this, will it fit well in the firebase console authentication list, just like a successful Google login? with uid?

CodePudding user response:

As Dharamarj commented, you'll typically either use the ID from the 3rd party system and prefix it with something that identifies the provider, or you generate you own (unique) IDs.

In the latter case, if you are using a 3rd party auth system, you'll want to maintain a mapping from your UIDs to the identifiers of the 3rd party system.

CodePudding user response:

The custom tokens are generally used when you have your own authentication system but still want to use Firebase authentication to use feature like auth in security rules.

I plan to do other social sign in & up that firebase does not provide.

In such cases, ideally you must be storing some UID in your database (where you store users' information) to identify users. You should pass the same UID in createCustomToken() so it's used in Firebase auth as well and a Firebase Auth User is associated with your custom auth user.

  • Related