Recent Topics

How to add a login button(sign in with google) on Bagisto(velocity theme).



  • I had done these things

    1. Obtain these credentials form google and add these to .env.
    GOOGLE_CLIENT_ID 
    GOOGLE_CLIENT_SECRET 
    GOOGLE_REDIRECT 
    
    1. Add routes in web.php
    Route::get('/redirect','Auth\[email protected]');
    Route::get('/callback','Auth\[email protected]leRedirect');
    

    3.Add a controller in LoginController.php

    use Hash;
    use Laravel\Socialite\Facades\Socialite;
    use Illuminate\Support\Str;
    use App\User;
    
    //Send the user request to google
    public function google(){
            return Socialite::driver('google')->redirect();
    }
    
    //get the auth request from the google to authenticate 
    public function goo gleRedirect(){
        $user = Socialite::driver('google')->stateless()->user();
    
        $user = User::firstOrCreate([
            'email' => $user->email
        ], [
            'name' =>  $user->name,
            'password' => Hash::make(Str::random(24))
        ]);
        Auth::login($user, true);
        return redirect('/dashboard'); 
    }
    

    I cant able to understand how to add UI button(login with google) and redirect it to

    /redirect
    


  • Hey Prashant,

    I really appreciate your efforts, you could add your options here.

    Let me know if you have any further query.

    Thanks!


Log in to reply