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

shoaibali's avatar

Laravel socialite social login API for mobile application

Hi,

I hope all members of this family having a great day. So i have created the Ecommerce website . .I have integrated the google social login with socialite plugin of laravel.

Meanwhile we are developing the Mobile application for it. Can anybody here guide me how to create the API for it? I have created the logic for the API but on a callback Its getting into the web class callback function and that functionis not intended for the API as for the API we need to have the success JSON response.

Can anybody please let me know the standard flow to solve this problem?

Here is the web class code that is working fine..

 public function redirect(){
        return \Socialite::driver('google')->redirect();
    }

     public function callbackGoogle()
    {
        try {
            $google_user = \Socialite::driver('google')->user();
            $fetchedUser = User::where('email', $google_user->getEmail())->first();
            if (!$fetchedUser) {
            $newUser = User::create([
                    'name' => $google_user->getName(),
                    'email' => $google_user->getEmail(),
                    'google_id' => $google_user->getId(),
                ]);

                Auth::login($newUser, true);
                return redirect()->intended('dashboard');
            } else {
                Auth::login($fetchedUser, true);
                return redirect()->intended('dashboard');
            }
        } catch (\Throwable $th) {
            dd('Oops! Something Went Wrong'.$th->getMessage());
        }
    }

Please share your code OR logic if anyone ever build the API for social login for mobile application.. How can we solve this? and how would I test it with POSTMAN?

0 likes
0 replies

Please or to participate in this conversation.