Specify UserId Format When Creating Login Via OAuth2 With Firebase

Viewed 302

Perhaps Firebase gave me enough rope to hang myself with.

When creating a user via provided email and password, I am able to also provide the user_id.

Great. Since most of my primary keys in my database are uuid/guid, I thought it would be swell to make my user_id in my users table a uuid pk.

That worked.

Until I let the user authenticate via a third-party. Firebase came back having created my lovely user. With a Firebase UserId.

Which is not a uuid.

And now I find myself contemplating having to redesign the userId field in my database back to text type, because the Firebase UserId is not a uuid.

Is there a way to tell Firebase to make all user_id values be guids? I've poked around a wee bit but I don't see options when using OAuth2 to tell Firebase, "And when you come back with a user, make that user_id a uuid/guid, please..."

Edit: Perhaps I wasn't clear. I was/am using the Firebase UID as my pk, not, for example, the user's email address. But if I can only control the value/format of that UID when I'm providing email/pwd to create users (and not when authenticating via 3rd party OAuth2) then I cannot assume my preferred format.

2nd Edit:

When creating users via email/pwd, I do so via Firebase Admin SDK. The browser passes the email/pwd to the API, and the API creates the user--with full control over UID.

private async Task<UserRecord> AddFirebaseLogin(UserForCreation userForCreation)
{
  UserRecordArgs args = new UserRecordArgs()
  {
    Uid = Guid.NewGuid().ToString(),
...

However when the browser redirects to 3rd party OAuth, the UID comes back already in the authentication token, and I think I've missed my chance to say what format I'd like that UID to be in.

let provider = new firebase.auth.OAuthProvider('microsoft.com');
...
return this.afAuth.auth
  .signInWithPopup(provider)
  .then((res) => {
     this.ngZone.run(() => {
        const userData = {
          uid: res.user.uid,
...

I am thinking it's of small value to have the privilege of setting the UID when creating users directly in one situation if one does not have this level of control in any of the other authentication methods.

All I did was create heartache for myself when I ran with the freedoms afforded me when I was creating users myself with email/pwd.

Maybe I'm missing something.

1 Answers

It's not possible to control the content or format of the UIDs coming from Firebase Authentication. It generates unique strings, and they need to be accepted as they are. You can be sure they are unique within your project, and are safe to use as primary keys in a database.

Related