Laravel Vue.js - 服务器重新启动后,帐户不会注销



Laravel+Vue.jsSPA(单页应用程序(中,我通过命令提示符下的命令php artisan serve启动服务器。例如,对于页面profile/edit,我在web.php中有:

Route::get('/profil/edit','UserController@edit_profile')->name('edit_profile');
Route::get('/login','UserController@login')->name('login');
Route::post('/login_now','UserController@login_now')->name('login_now');

我没有使用默认的auth控制器方法来登录,因为它们似乎不适合ajaxaxios请求。因此,我使用了自己的控制器方法,并采用了内置的登录和注销功能方法。

router.js,我有:

export default new VueRouter({
mode: 'history',
routes: [
......
{ path: '/profile/edit', component: EditProfile, name: 'edit_profile'
, meta: {
auth: true,
title: 'Nogor Solutions - Edit Profile '
}}
.....
],
scrollBehavior (to, from, savedPosition) {
return { x: 0, y: 0 }
}
});

UserController,我有:

public function __construct(){
$this->middleware('auth', ['except' => [
'index',
'login',
'login_now'
]]);
}
public function edit_profile(){
$user=User::find(1,['name','email','address','country_code','national_number',
'phone_number','dob','profession','photo']);
JavaScript::put([
'user_profile' => $user
]);  //  This makes the variable user_profile available in blade and vue files

return view('app');
}//end of function edit_profile

app.blade.phpviews目录中,我在最开头有:

<?php echo
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: text/html');?>

现在我首先运行命令npm run dev然后命令php artisa serve. 然后当我点击地址127.0.0.1:8000时,它会将我带到登录页面。从那里登录后,我可以转到profile/edit页面。

目前为止,一切都好。现在从命令提示符下,如果我使用Ctrl+C取消当前正在执行的命令,那么已经在运行的服务器将停止。让我再次使用php artisan serve启动服务器。这次,当我点击已经在浏览器中打开的URL"/profile/edit"时,该页面不会再次将我带到登录页面。它只是显示在那里。

上述行为是否可取?那里有任何安全问题或架构问题吗?服务器重新启动后,当我点击相同的 URl (profile/edit( 时,如何使页面重定向到登录?

它可能正在使用cookie(或其他东西(跟踪您的登录状态。您是否尝试过清除cookie和缓存以查看是否会将您带回登录页面?

如果是这样,那么它就是设计的一部分,你不需要担心。

最新更新