无法获得laravel饼干laravel_token而消耗自己的API

问题描述 投票:0回答:1

Cookie是在浏览器中使用,但不能得到它甚至不能检查它是否存在。 qazxsw POI

在laravel和vuejs应用程序的工作,我现在用的护照进行身份验证。我enter image description here在kernel.php所以我加入了CreateFreshApiToken中间件

vuejs被创建和发送成功laravel_token Cookie,但使用vuejs或JavaScript它,我无法阅读。

因为我不能检查,如果cookie是可用与否,如果用户登录或不我无法检查。

我怎么会告诉vuejs该用户登录并采取预定航线?

现在我在localStorage的节约和的access_token每个请求发送,但我在寻找一个解决方案,它可以帮助使用laravel内置laravel_token cookie来验证和授权用户。

更多细节

如果我运行控制台命令然后我得到响应

consuming own api with vuejs

document.cookie.match('XSRF-TOKEN')

返回null

我认为,在顶部的显示图像中的勾号图标是使它私人或东西,使得它无法进入的迹象。

更新

我发现从网上document.cookie.match('laravel_token') 的东西,但是我还是想知道我怎么能告诉vuejs应用程序,用户登录或没有?

更新2

现在我的头手动vuejs发送和的access_token它是工作的罚款。

enter image description here
laravel api cookies vuejs2 laravel-passport
1个回答
0
投票

周围一点点的工作将是你实现你的LoginController的身份验证方法,并返回一个JSON成功代码。然后,您可以收到此代码和存储。

if(localStorage.getItem('laravel_token') !== 'undefined' &&  !! localStorage.getItem('laravel_token') == true){

    window.axios.defaults.headers.common['Authorization'] = 'Bearer '+ localStorage.getItem('laravel_token')
}

Ysing值得...

public function authenticated(Request $request, $user)
{
    // return redirect()->intended($this->redirectPath());
    return json_encode(['authenticated' => true]);
}
© www.soinside.com 2019 - 2024. All rights reserved.