Search code examples
firebasefirebase-authenticationuuid

Is it possible to shorten firebase auth UIDs?


I've started designing a referral system and wanted to use firebase auth UIDs as the referral code for each user, however they're longer than I'd like and also not guaranteed to stay small. I've looked into some libraries for short text compression, hashing, etc; But none seem to satisfy my needs. I've recently came across the lovely short-uuid pkg on npm but unfortunately it doesn't seem it works with firebase UIDs(because those aren't UUIDs) but i've been looking for a possible solution that doesn't involve keeping a lookup table of custom IDs to UIDs.

So the real question: is there any good way to compress a short string programmatically and then decompress?


Solution

  • As @FrankVanPuffelen explained there is no way for you to control the UIDs that Firebase Authentication automatically generates.

    But with the createUser() method of the Admin SDK you can define which UID you want to assign to a new user. As explained in the doc, "if you instead want to specify your own UID for the new user, you can include it as an argument passed to the user creation method"

    await admin.auth().createUser(
      {
        uid: 'some-uid',
        email: 'user@example.com',
        password: '....',
      }
    );
    

    You can run this code in a Cloud Function or on a server you own.

    Of course, you need to ensure that the user's UID is unique for each user.