Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FareedR's avatar

Redirect User using API for Mobile App

How can i redirect successful login user to their dashboard ? should i setting it from mobile app ? or i need to change return response to return redirect()->route('dashboard') ? sorry . first time in API with mobile app .

//controller
public function login(Request $request)
    {
        $request->validate([
            'email' => "required",
            'password' => "required"
        ]);

        $credentials = request(['email','password']);

        // Check credentials
        if(!Auth::attempt($credentials)){
            return response()->json([
                'message' => 'Incorrect password or email. Please try again'
            ],401);
        }elseif(!Auth::user()->email_verified){
            return response()->json([
                'message' => 'Please verify your e-mail address'
            ],401);
        }
        else{
            $user = $request->user();

            // Create user token
            $tokenResult = $user->createToken('Personal Access Token');
            $token = $tokenResult->token;
            $token->save();
            
            return response()->json([
                'message' => 'Successfully Login',
                'token' => $tokenResult
            ],201);
            
        }
0 likes
2 replies
steve_laracasts's avatar

Um, generally I would use the API for calls that do not require loading a new page and general routing for calls that do require a change of page.

Nice and straightforward then.

I know this doesn't answer your question and I guess there are ways you could refresh the page after an API call, but this just seems like a difficult way to go about things.

FareedR's avatar

is there any source that i can refer on authentication process using API ?

Please or to participate in this conversation.