简体   繁体   English

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

[英]Laravel Vue.js - after server restart, account does not log out

In a Laravel + Vue.js SPA (Single Page Application ), I start the server by the command php artisan serve in command prompt.Laravel + Vue.js SPA(单页应用程序)中,我通过命令提示符php artisan serve启动服务器。 For example, for the page profile/edit , I have in web.php :例如,对于页面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');

I did not use the default auth controller methods for log in purpose because they did not seem to be suitable for ajax requests with axios .我没有使用默认的auth控制器方法进行登录,因为它们似乎不适合使用axios ajax请求。 Therefore I used my own controller methods and took to the built in methods for log in and log out functions.因此,我使用了自己的控制器方法,并采用了登录和注销功能的内置方法。

In router.js , I have :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 }
      }
    });

In UserController , I have :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

In app.blade.php inside views directory , I have at the very beginning :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');?>

Now first I run the command npm run dev and after that the command php artisa serve .现在首先我运行命令npm run dev ,然后npm run dev命令php artisa serve Then when I hit the address 127.0.0.1:8000 , it takes me to the log in page.然后当我点击地址127.0.0.1:8000 ,它会将我带到登录页面。 After login from there I can go to the profile/edit page.从那里登录后,我可以转到profile/edit页面。

So far so good.到现在为止还挺好。 Now from the command prompt, if I cancel the current executing command with Ctrl + C , then the server already running stops.现在从命令提示符,如果我用Ctrl + C取消当前正在执行的命令,那么已经运行的服务器会停止。 Let me start the server with php artisan serve again.让我再次使用php artisan serve启动服务器。 This time when I hit the URL '/profile/edit' which remains already open in the browser, the page does NOT take me to the login page again.这一次,当我打的网址“/型材/编辑”这仍然是在浏览器已经打开,页面带我到登录页面一次。 It just gets displayed there.它只是显示在那里。

Is the mentioned behavior desirable?提到的行为是可取的吗? Any security concern or architecture issue there?那里有任何安全问题或架构问题吗? How can I make the page redirect to login when I hit the same URl ( profile/edit ) after server restart?当我在服务器重启后点击相同的 URl ( profile/edit ) 时,如何使页面重定向到登录?

It might be tracking your logged in status using cookies (or something).它可能会使用 cookie(或其他东西)跟踪您的登录状态。 Have you tried clearing cookies and cache to see if that takes you back to the login page?您是否尝试过清除 cookie 和缓存以查看是否会将您带回登录页面?

If it does, then it's part of the design and you don't need to be concerned.如果是这样,那么它就是设计的一部分,您无需担心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM