【发布时间】:2021-07-13 01:32:14
【问题描述】:
我是 vuejs 的初学者。我正在使用 Vuejs 使用 laravel sanctum 作为基于令牌的身份验证的包来执行我的第一个应用程序。我的问题是当用户登录并保持非活动状态几个小时而没有从应用程序注销时,尝试访问受保护的路由后出现 401(未经授权)错误。我必须注销并再次登录才能完成我的工作。
我正在使用 vuex 状态管理库来保存应用程序状态。
routes/api.php
Route::post('/login','API\AuthController@login');
Route::middleware('auth:sanctum')->group(function (){
Route::get('/logout','API\AuthController@logout');});
以下是我的登录方式
axios.get('/sanctum/csrf-cookie').then(response => {
// Login...
this.$store.dispatch('login',credentials)
.then((res) => {
this.$store.commit("SET_LOADING",false);
if( this.isAuthenticated && config.getToken() !== 'undefined'){
this.$router.push({ name: 'home'});
window.reload;
}
});});
我的 vuex store.js
export default new Vuex.Store({
modules: {
auth
},
plugins: [
createPersistedState(
{
storage: window.localStorage
}
)],})
我试图将我的令牌存储在本地存储中,但我认为这不是最好的方法...... 我想要的是让用户登录很长时间,直到他/她退出
【问题讨论】:
-
您能告诉我您的
config/sanctum.php文件中expiration的值吗? -
config/sanctum.php中expiration的值为null
标签: laravel vue.js vuex laravel-sanctum