[英]Laravel 5.2 Auth::check() is not working even when Auth::attempt() succeeds
public function login($local=false,$data=[])
{
$validator = Validator::make(($local)?$data:Request::all(), [
'username' => 'required',
'password' => 'required',
]);
if ($validator->fails()) {
return Response::json(array('status'=>'0','message'=>'Invalid parameters'));
}
if(Auth::attempt(($local)?$data:Request::all()))
{
//dd(Auth::user());
return Response::json(array('status'=>'1','message'=>'User logged in successfully'));
}
return Response::json(array('status'=>'1','message'=>'User log in failed'));
}
this works and shows successfully logged in, but when i tried accessing the details of the authenticated user, it returns null. 这工作并显示成功登录,但当我尝试访问经过身份验证的用户的详细信息时,它返回null。
if(!Auth::check())
{
return Response::json(array('status'=>'0','message'=>'User not logged in'));
}
Any suggestions will be appreciated. 任何建议将不胜感激。 Thanks
谢谢
Auth::check()
will work if request coming from same server eg: www.laraapi.com
如果请求来自同一服务器,
Auth::check()
将起作用,例如: www.laraapi.com
As per my understanding, you have to make some token based authentication, means 根据我的理解,你必须进行一些基于令牌的身份验证
username=>'testuser',
password=>'123456987',
'userSecrectToken'=>'asd88225asdaweqs8899eqweiou'
once user is authenticated, pass secret token with userid/username and request type 用户通过身份验证后,使用userid / username和请求类型传递秘密令牌
eg: 例如:
'username'=>'testuser',
'userSecrectToken'=>'asd88225asdaweqs8899eqweiou'
'requestType'=>'getUserOrders',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.