I'm trying to show "logged in" message after user logged in to my application, actually when user attempt to login for the first time I will give him/her a jwt token and I want to check if the user is logged in if user attempt to login more than once.
This is the part I have problem :
if($this->attemptLogin($request)){
return ($this->loginCounter > 0) ? response()->json('Logged in', 200) : ($this->CreateToken($request));
}
But when attemptLogin is called which will run below code it will redirect user if user is logged in :
protected function attemptLogin(Request $request)
{
return $this->guard()->attempt(
$this->credentials($request), $request->has('remember')
);
}
IS there any way to override this ? and return "you are logged in" in response instead of redirecting to a view ?
FYI : I have customized laravel auth scafold , but this part is still making problem for me. I'm using laravel 5.3
I've solved this problem by replacing
return redirect('/home');
with proper json response in RedirectIfAuthenticated.php file :
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
$json = [
'success' => true,
'code' => 200,
'message' => 'You are Logged in.',
];
return \Response::json($json,200);
}
return $next($request);
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community