如何在Firebase身份验证网站中存储用户名和photourl [英] How to store username and photourl in firebase auth web

查看:101
本文介绍了如何在Firebase身份验证网站中存储用户名和photourl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试Firebase身份验证.我要在用户注册时存储照片网址和用户名.我的注册代码-

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);
    });

有人可以告诉我如何在注册时添加用户名和照片网址.我知道我可以在firebase数据库中进行收藏,但是我读过某个地方,用户名和照片网址也可以保存在firebase auth

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

推荐答案

Firebase身份验证没有存储用户名的用户属性.您必须自己将其存储在数据库中,并确保字符串是唯一的.

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.

您可以使用 updateProfile()存储个人资料图片的URL

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.

通常,如果您有要为每个用户存储的自定义信息,则应使用登录用户的唯一ID在数据库中执行此操作.这将为您提供完全控制权,而不是取决于Firebase Auth提供的功能(不是很多). Auth的目的是验证用户的身份,而不是存储每个用户的信息.

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.

这篇关于如何在Firebase身份验证网站中存储用户名和photourl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆