Level 2
@elkebirmed did you find a way to solve this?
I want to redirect to an OAuth2 socialite provider when a user clicks a button, but nothing is working.
<?php
namespace App\Http\Livewire\Pages;
use App\Models\User;
use App\Models\Country;
use Livewire\Component;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Laravel\Socialite\Facades\Socialite;
class Register extends Component
{
public $name;
public $email;
public $username;
public $country;
public $password;
public $password_confirmation;
public $user;
public function submit()
{
$this->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'username' => ['required', 'string', 'regex:/^\S*$/u', 'min:3', 'max:255', 'unique:users'],
'country' => ['required', 'exists:countries,code'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
User::create([
'name' => $this->name,
'email' => $this->email,
'username' => $this->username,
'country_id' => Country::where('code', $this->country)->first()->id,
'password' => Hash::make($this->password),
]);
if (Auth::attempt([
'email' => $this->email,
'password' => $this->password,
])) {
return redirect()->intended('welcome');
}
}
public function redirectToGithub()
{
return Socialite::driver('github')
->scopes(['read:user'])
->redirect();
}
public function render()
{
$countries = Country::all()->sortBy('name');
return view('livewire.pages.register', compact(['countries']));
}
}
<button wire:click.prevent="redirectToGithub">Github</button>
Please or to participate in this conversation.