[英]How to save user data when they log in using firebase authentication?
I am using Firebase Authentication to allow users to log into my Angular app.我正在使用 Firebase 身份验证来允许用户登录我的 Angular 应用程序。
Below is the login()
method in my AuthService
:下面是我的
AuthService
中的login()
方法:
login(email: string, password: string) {
return from(firebase.auth().signInWithEmailAndPassword(email, password));
}
This is working fine, but now I am trying to store the user's data when they log in, so that they're not accidentally logged out when they refresh the app.这工作正常,但现在我试图在用户登录时存储他们的数据,以便他们在刷新应用程序时不会意外注销。
Can someone please tell me how I can use the object returned in the above method to ensure a user remains logged in unless they choose to log out of the app?有人可以告诉我如何使用上述方法返回的 object 来确保用户保持登录状态,除非他们选择退出应用程序?
When you call firebase.auth().signInWithEmailAndPassword(email, password)
then the user will stay logged in. You can check if the user is null or not by using:当您调用
firebase.auth().signInWithEmailAndPassword(email, password)
时,用户将保持登录状态。您可以使用以下命令检查用户是否为 null:
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
} else {
// No user is signed in.
}
});
https://firebase.google.com/docs/auth/web/manage-users https://firebase.google.com/docs/auth/web/manage-users
If user is signed in,then just direct the user to the pages after login.如果用户已登录,则只需在登录后将用户定向到页面。
You have to persist the data.您必须保留数据。 Look this doc:
看这个文档:
https://firebase.google.com/docs/auth/web/auth-state-persistence https://firebase.google.com/docs/auth/web/auth-state-persistence
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.