我通过VueJS创建登录表单。登录后,我可以将用户信息获取到VueJS。但是它没有登录到Laravel系统。我创建了用于登录功能的API
public function login()
{
// SOME CODE to check email/password here
if( Auth::attempt(['email' => request('username'), 'password' =>request('password')], request('remember'))) {
// Format the final response in a desirable format
return response()->json([
'status' => 200,
'authUser'=> Auth::user()
]);
}else {
return response()->json([
'error' => true,
'message' => 'Not correct'
], 200);
}
}
Auth :: attempt仍然有效,因为我尝试返回'authUser'=> Auth :: user(),然后在控制台中获得了用户数据。 但是它没有登录到Laravel系统。似乎两个会话是不同的。如何通过VueJS登录到Laravel?
答案 0 :(得分:0)
您使用过CSRF-TOKEN吗?
<meta id="token" name="token" content="{{ csrf_token() }}">
Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('content');
答案 1 :(得分:0)
$user = App\User::find(1);
// Creating a token without scopes...
$token = $user->createToken('Token Name')->accessToken;
// Creating a token with scopes...
$token = $user->createToken('My Token', ['place-orders'])->accessToken;