jeudi 9 septembre 2021

Callback 404 not found in login with google with Socialite

I have this link on my modal popup

<li><a href="" target="_blank"><i class="fab fa-google-plus-g"></i></a></li>

and routes is

Route::get('google', 'SocialiteAuthController@googleRedirect')->name('auth/google');
Route::get('/auth/google-callback',  'SocialiteAuthController@loginWithGoogle');

enter image description here

Services.php

'google' => [
    'client_id' => 'XXXXXXXXXXXXXXXX.apps.googleusercontent.com',
    'client_secret' => 'XXXXXXXXXXXXX',
    'redirect' => 'http://localhost:8000/login/google/callback',
],

Controller:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\User;
use Socialite;
use Illuminate\Support\Facades\Auth;
use Exception;

class SocialiteAuthController extends Controller
{
    public function googleRedirect()
    {
        return Socialite::driver('google')->redirect();
    }

     /**
     * Facebook login authentication
     *
     * @return void
     */
    public function loginWithGoogle()
    {
        try {
            $googleUser = Socialite::driver('google')->user();
            $user = User::where('google_id', $googleUser->id)->first();

            if($user){
                Auth::login($user);
                return redirect('/home');
            }

            else{
                $createUser = User::create([
                    'name' => $googleUser->name,
                    'email' => $googleUser->email,
                    'fb_id' => $googleUser->id,
                    'password' => encrypt('test@123')
                ]);

                Auth::login($createUser);
                return redirect('/home');
            }

        } catch (Exception $exception) {
            dd($exception->getMessage());
        }
    }
}

Guard :

 'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'user' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

but when i login i'm getting this page 404 not found

enter image description here

Any solution, Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3nh0XGA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire