我希望我的应用程序在成功注册或登录后重定向到仪表板并显示一条消息“欢迎(用户名)”。我能做什么?
我还没有找到任何关于如何去做的指南......
假设您正在使用 Firebase 身份验证,并且“用户名”是指显示名称,您可以使用 Auth 中的“currentUser”值检索它以及其他用户数据。然后,它具有使您可以访问某些用户数据的值。文档中的示例代码:
import { getAuth } from "firebase/auth";
const auth = getAuth();
const user = auth.currentUser;
if (user !== null) {
// The user object has basic properties such as display name, email, etc.
const displayName = user.displayName;
const email = user.email;
const photoURL = user.photoURL;
const emailVerified = user.emailVerified;
// The user's ID, unique to the Firebase project. Do NOT use
// this value to authenticate with your backend server, if
// you have one. Use User.getToken() instead.
const uid = user.uid;
}