My app structure requires me to log in user with a specific Uid
.
Can i do that in Firebase Auth.
I mean , If i want to create a user with uid=1
.
which i will send along with email and password.
Is it possible ?
You can set UID for the Firebase user if you use a custom token to authenticate. See this https://firebase.google.com/docs/auth/admin/create-custom-tokens#create_custom_tokens_using_a_third-party_jwt_library
Here's the example using Ruby (:uid => uid
)
require "jwt"
# Get your service account's email address and private key from the JSON key file
$service_account_email = "[email protected]"
$private_key = OpenSSL::PKey::RSA.new "-----BEGIN PRIVATE KEY-----\n..."
def create_custom_token(uid, is_premium_account)
now_seconds = Time.now.to_i
payload = {:iss => $service_account_email,
:sub => $service_account_email,
:aud => "https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit",
:iat => now_seconds,
:exp => now_seconds+(60*60), # Maximum expiration time is one hour
:uid => uid,
:claims => {:premium_account => is_premium_account}}
JWT.encode payload, $private_key, "RS256"
end
Yes, you can with admin sdk:
admin
.auth()
.createUser({
uid: 'some-uid',
email: '[email protected]',
phoneNumber: '+11234567890',
})
.then((userRecord) => {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully created new user:', userRecord.uid);
})
.catch((error) => {
console.log('Error creating new user:', error);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With