【发布时间】:2017-12-12 14:51:11
【问题描述】:
我有一个 Angular 应用程序,它使用 firebase 对客户端上的用户进行身份验证。这似乎工作正常。
export class AuthService {
user$: Observable<firebase.User>;
constructor(private af_auth: AngularFireAuth) {
this.user$ = this.af_auth.authState;
this.user$.subscribe(user => {
// do something with the firebase user
});
}
}
我还有一些基于服务器的东西在 node.js 中使用 express 运行。我想尝试验证点击我的端点的用户是否已经通过 firebase 对我的应用程序进行了身份验证。我可以这样做吗?
我想在 express 中有一个类似这样的路由处理程序:
var firebase_app = firebase.initializeApp(firebase_config);
auth.isAuthenticated = function (req, res, next) {
// I had seen a suggestion to do the following, but currentUser is always null here.
var user = firebase_app.auth().currentUser;
if (user !== null) {
// Authenticated with my app?
req.auth_user = user;
next();
} else {
res.status(401).send({error: 'Nope'});
}
};
如何从快速路由处理程序中得知我的用户已登录到我的应用程序?
【问题讨论】:
标签: firebase firebase-authentication