[英]how to modify laravel middleware to work with firebase authentication
我在laravel和firebase中工作,作为身份验证和数据存储的后端。 我正在使用firebase提供的js代码来登录用户
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
});
问题是我想保护我的路由免受非认证用户的影响。 我如何在我的中间件中检查用户是否登录,因为js将当前用户的uid存储在localStorage中。 我是否必须为此目的使用单独的数据库? 请帮我走正确的方向。
你必须打电话:
auth.currentUser.getIdToken().then(function(token) {
// The Firebase id token is returned here.
// You will have to send that along your requests to your server.
// Keep in mind this is a short lived token
// You have to call getToken each time you need it in case
// it is auto refreshed underneath.
});
目前,Firebase提供了node.js和java后端库来验证令牌(以检查用户是否已登录)。 https://firebase.google.com/docs/auth/server
一个php库正在开发中。 准备就绪后,它应该提供类似的功能,用于铸造自定义令牌和验证Firebase ID令牌。
您可以使用此https://github.com/vinkas0/firebase-auth-laravel laravel包通过firebase进行身份验证
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.