Ved21212
4 months ago
403
7
Laravel

Session does not regenerate after login..

Posted 4 months ago by Ved21212

Hello team, I am trying to logout and generate a new session id on logout but fail to do so..can anyone help me with that?

Following is what I have tried, Please correct me if I am wrong!! Login:

  public function LoginFront(Request $request){
        $attempt = [];
        $login_email = $request->login_email;
        $login_password = $request->login_password;

        $attempt = Auth::attempt(array('email' => $login_email, 'password' => $login_password));

        //dd($attempt);

        if($attempt == true){
            $ecomm_id = Auth::user()->id;
			
			if($ecomm_id == 1){			
				$attempt = false;
            	return response()->json($attempt);	
			}else{
                
                $request->session()->regenerate();
				$request->session()->put('ecomm_id',$ecomm_id);
            	return response()->json($attempt);
			}
            
        }else{
            return response()->json($attempt);
        }

    }

Logout:

 public function LogoutFront(Request $request){

            Auth::logout();
            Session::flush();
            $request->session()->regenerate();
                        return redirect('/');
            // return '1';

        }

Thanks

Please sign in or create an account to participate in this conversation.