I'm creating an application with flutter and using firebase for authentication in data storage (possible more).
I have an auth onCreate cloud function which adds some user information to my realtime database whenever a user is created. But, I also want to set a displayName and photoURL when the user is created because if I update the profile info after, the onCreate won't be triggered. I also don't want users to be able to write to this part of the database.
Is there any method I can user to pass an displayName and photoURL when the user is created? Currently, I'm just creating the user with an email and password.
Thanks.
Instead of creating the users directly from the client, you can use a callable function to create users using the Admin SDK, which includes displayName and photoURL in its options.
Related
I'm working on an android app in kotlin and i created a login and register with firebase authentication, now when i want to access the users info in the database using the uid i got with this FirebaseAuth.getInstance().currentUser?.uid.toString() i noticed that the current uid is deferent from the uid that the function createUserWithEmailAndPassword() gave the users when it created them and inserted the to the database.
my question is how do i get the original uid from createUserWithEmailAndPassword().
i was thinking of saving the uid in a global string in the function createUserWithEmailAndPassword() but I'm sure there's a better idea .
I'm sorry if my question is basic question...
is UID in firebase automatically created when we implement .setUid() at the first user sign-up account? and if we are login to that user account and implement .getUid(), can we retrieve the same UID?
I use Android Studio and Kotlin as programming language
No matter how you implement authentication on your app, firebase will automatically set a uid for each account created. If you go to the auth section of your firebase console and manually add an account, you will see on the right hand side a uid generated for that account.
To reference this uid within your code the uid does not need to be stored in any database solution for the uid is attatched to the account within FirebaseAuth..
To pull the uid for reference once the user has signed in, first you need to set the auth global variable..
private lateinit var auth: FirebaseAuth
Then anywhere within the scope of your functions you can set your uid reference variable like this..
val myUid = FirebaseAuth.getInstance().currentUser.uid;
I am setting up a firebase authentication system with firebase. As I wanted it to be username and password, I needed to do it myself.
The workflow is this:
Cloud function gets username and password
It get the corresponding email from firestore
It use signInWithEmailAndPassword() to sign in and get the user data
It it createCustomToken() with the user uid and data that I need
It returns the token to the webclient
Webclient use signInWithCustomToken() with the token
The onAuthStateChanged callback gets trigger and setup my data from the user data
This process works great when deploy in firebase.
The problem is that when I want to use it with the firebase emulator, the user variable on step 7 has no data (no email, no displayName, etc are all set to null). I know that custom token are not signed when generated from the emulator, but is there a way to still get the data out of them?
Thanks
Im triying to use firebase in my app but I have a doubt about registration process, I declared an User collection, but when I sign up with google or facebook, the data is stored in Authentication, I want create an user but besides the fiels email and password, also with a fields like address, role, city and use the createUserWithEmailAndPassword method , to create the user with all those fields, is there a way to do that?
Auth only creates it's own entry to its own table. so you should first get these details from the user and send them to user collection manually.
You can create a new user object adding all these details into it and call this:
this.fireStore.collection("users")
.doc(user.id)
.set(user);
Due to security reasons, I wouldn't recommend storing the password in the db though.
If I use the user registration and login through the firebase authentication, the user information are stored in the firebase database side. How can I get the user information (such as FirstName, LastName, Gender and etc.) and store in my own database? Is it use the access token to call my API to check the user identity?
I suggest to use a cloud functions to triggers when user was created.
exports.userCreate = functions.auth.user().onCreate((user) => {
const email = user.email; // The email of the user.
const displayName = user.displayName; // The display name of the user.
// Write insert email, displayName, ... to your own database.
});
Ref: https://firebase.google.com/docs/functions/auth-events
When a user registers for your app using Firebase Authentication, no information is sent to your Firebase database by default...they only have an Auth account.
You need to manually collect and send information to your database. Once a user is authenticated within your app, you can listen for their Auth user info with onAuthStateChanged.
Lotsa folks then use the uid as the key in their database and store profile info below that.