Support the ongoing development of Laravel.io →
Configuration Authentication Requests

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

Last updated 3 years ago.
0

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);
    }
0

Sign in to participate in this thread!

Eventy

Your banner here too?

anonymox anonymox Joined 16 Oct 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.