Answers for "laravel remember"

PHP
0

how remember me in laravel working

$remember_me = $request->has('remember') ? true : false;



    if (auth()->attempt(['email' => $request->input('email'), 'password' => $request->input('password')], $remember_me))
    {
      $user = auth()->user();
      Auth::login($user,true);
    }else{

        return back()->with('error','your username and password are wrong.');

    }
Posted by: Guest on February-05-2021
1

laravel 8 remember me

/*
 This have a problem, for example:
 1. you login in browser/device 1 with "remember me" enabled,
 2. and login with the same user on another browser/device 2 also with "remember me" enabled.
 
 if you logout that user in browser/device 2, 
 a user in browser/device 1 'remember me' token will be invalid
 and automatically logouted by default if token invalid.
 
 to prevent this, in the logout function use this instead:
 */

	public function logout(){
        // Auth::logout();
      	Auth::logoutCurrentDevice(); // use this instead of Auth::logout()
        
        request()->session()->invalidate();
    
        request()->session()->regenerateToken();
    
        return redirect('/login');
    }
Posted by: Guest on October-09-2021

Browse Popular Code Answers by Language