Akash Shyam
Akash Shyam

Reputation: 114

How to store username and photourl in firebase auth web

I am trying out firebase auth. I want to store a photo-url and a username when the user signs up. My code for signing up -

const email = signupForm['email'].value;
const password = signupForm['password'].value;

auth
    .createUserWithEmailAndPassword(email, password)
    .then((cred) => {
        console.log(cred);

        alert('done');

        signupForm.reset();
    })
    .catch((error) => {
        console.log(error);
        alert(error);
    });

Could someone tell me how to add username and photo-url in signup. I know I can make a collection in a firebase db but I read somewhere that username and photo-url can also be saved in firebase auth

Upvotes: 1

Views: 1740

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317497

Firebase Authentication doesn't have a user property that stores username. You would have to store that on your own, in a database, and make sure the string is unique.

You can store a profile picture URL using updateProfile(). It will not store the image for you - you can only provide a URL. If you need to store the image file itself, tou should probably consider using another product for that, such as Cloud Storage.

Typically, if you have custom information to store per user, you should do that in a database using the unique ID of the user signed in. This gives you full control, rather than depending on what Firebase Auth provides (which is not much). The purpose of Auth is to validate the user's identity, not store per-user information.

Upvotes: 3

Related Questions