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

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

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.php目录内的views中,我一开始就有:

    <?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'时,该页面再次NOT将我带到登录页面。它只是在那里显示。

上述行为是否合乎需要?那里是否存在安全问题或体系结构问题?服务器重启后,当我遇到相同的URl(profile/edit)时,如何使页面重定向到登录?

laravel vue.js session redirect logout
1个回答
0
投票

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

[如果有,那么它就是设计的一部分,您无需担心。

© www.soinside.com 2019 - 2024. All rights reserved.