Search code examples
firebase-realtime-databaseswift4userid

(Swift 4) How to generate custom auto id in firebase?


How to generate custom auto id in Firebase? I using swift 4.

now my project when sign up a user in firebase. the id will like this: user_id: 25ERcRyKtAR5IYPBI9XzJLu8I3F2

I need to set up a search center for admin so i need to make the id sample.

I want the id like this: (start with (18xxxxxx) and 8 number.)

user_id: 18435237
user_id: 18947232
user_id: 18451323
user_id: 18749325

Solution

  • The UID of a user account is determined by the provider that mints the tokens for that user account. There is no way to control the UIDs generated by any of the existing Firebase Authentication providers.

    If you want to control the UID, you'll have to create your own provider as shown here: https://firebase.google.com/docs/auth/ios/custom-auth

    I'd recommend against this though, and consider: what you are trying to accomplish by controlling the UID, and seeing if there's another way to accomplish this. Right now it reads like a XY problem, and above is the best I can tell you.