Laravel Auth::logout not removing remember me cookie

前端 未结 1 432
轻奢々
轻奢々 2021-01-12 14:34

So I have the lifetime of my sessions set to two weeks so users do not have to log in or out multiple times. However today I noticed something, if you log out it destroys yo

1条回答
  •  清酒与你
    2021-01-12 15:02

    It seems the cookie does not get unset automatically. However you can do this in your controller just before you return the redirect response after logout.

    public function getLogout() {
        // your code here
        .....
        // Get remember_me cookie name
        $rememberMeCookie = Auth::getRecallerName();
        // Tell Laravel to forget this cookie
        $cookie = Cookie::forget($rememberMeCookie);
    
        return Redirect::to('/')->withCookie($cookie);
    }
    

    Just remember to return the cookie with the redirect, otherwise it won't work.

    0 讨论(0)
提交回复
热议问题