[英]Laravel Vue.js - after server restart, account does not log out
在Laravel
+ Vue.js
SPA(單頁應用程序)中,我通過命令提示符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
控制器方法進行登錄,因為它們似乎不適合使用axios
ajax
請求。 因此,我使用了自己的控制器方法,並采用了登錄和注銷功能的內置方法。
在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
在views
目錄中的app.blade.php
,我在一開始就有:
<?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
,然后npm run dev
命令php artisa serve
。 然后當我點擊地址127.0.0.1:8000
,它會將我帶到登錄頁面。 從那里登錄后,我可以轉到profile/edit
頁面。
到現在為止還挺好。 現在從命令提示符,如果我用Ctrl + C取消當前正在執行的命令,那么已經運行的服務器會停止。 讓我再次使用php artisan serve
啟動服務器。 這一次,當我打的網址“/型材/編輯”這仍然是在瀏覽器已經打開,頁面不帶我到登錄頁面一次。 它只是顯示在那里。
提到的行為是可取的嗎? 那里有任何安全問題或架構問題嗎? 當我在服務器重啟后點擊相同的 URl ( profile/edit
) 時,如何使頁面重定向到登錄?
它可能會使用 cookie(或其他東西)跟蹤您的登錄狀態。 您是否嘗試過清除 cookie 和緩存以查看是否會將您帶回登錄頁面?
如果是這樣,那么它就是設計的一部分,您無需擔心。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.