Skip to content

Commit

Permalink
chore(app): Add Socialite
Browse files Browse the repository at this point in the history
  • Loading branch information
flemzord committed Aug 6, 2024
1 parent 81c7993 commit a45277c
Show file tree
Hide file tree
Showing 5 changed files with 426 additions and 177 deletions.
48 changes: 48 additions & 0 deletions apps/app/app/Http/Controllers/SocialiteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Http\Controllers;

use App\Actions\Fortify\CreateNewUser;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;

class SocialiteController extends Controller
{
public function redirect(): \Symfony\Component\HttpFoundation\RedirectResponse|\Illuminate\Http\RedirectResponse
{
return Socialite::driver('google')
->redirect();
}

public function callback(): \Illuminate\Foundation\Application|\Illuminate\Routing\Redirector|\Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse
{
$social = Socialite::driver('google')->user();

$check = User::where('google_id', $social->id)->first();
if ($check) {
Auth::login($check);

return redirect('/');
}

$user = (new CreateNewUser)->create([
'name' => $social->name,
'email' => $social->email,
'google_id' => $social->id,
'token' => $social->token,
]);

Auth::login($user);

return redirect('/');
}

public function localOnly(): \Illuminate\Foundation\Application|\Illuminate\Routing\Redirector|\Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse
{
$user = User::find(1);
Auth::login($user);

return redirect('/');
}
}
1 change: 1 addition & 0 deletions apps/app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"laravel/framework": "^11.9",
"laravel/jetstream": "^5.1",
"laravel/sanctum": "^4.0",
"laravel/socialite": "^5.15",
"laravel/tinker": "^2.9",
"livewire/livewire": "^3.0"
},
Expand Down
Loading

0 comments on commit a45277c

Please sign in to comment.