Skip to content

Commit

Permalink
Merge pull request #7 from Lakshan-Madushanka/master
Browse files Browse the repository at this point in the history
Make redirection to intended URL after authenticated and fix hard fix hard coded URL name.
  • Loading branch information
stevebauman committed Apr 25, 2024
2 parents 0038298 + ee4dacf commit 8f17546
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/UserProviderRedirector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@

class UserProviderRedirector implements ProviderRedirector
{
/**
* The URL to redirect to when unable to authenticate the user.
*/
public static string $unableToAuthenticateUserUrl = 'login';

/**
* The URL to redirect to when the user already exists.
*/
public static string $userAlreadyExistsUrl = 'login';

/**
* The URL to redirect to when unable to create the user.
*/
public static string $unableToCreateUserUrl = 'login';

/**
* The URL to redirect to when the user has been successfully authenticated.
*/
public static string $userAuthenticatedUrl = 'dashboard';

/**
* Redirect when unable to authenticate the user.
*/
Expand All @@ -21,7 +41,7 @@ public function unableToAuthenticateUser(Exception $e, string $driver): Redirect

$message = sprintf('There was a problem creating your %s account. Please try again.', ucfirst($driver));

return $this->redirector()->to('login')->with('flash', [
return $this->redirector()->to(static::$unableToAuthenticateUserUrl)->with('flash', [
'bannerStyle' => 'danger',
'banner' => $message,
]);
Expand All @@ -34,7 +54,7 @@ public function userAlreadyExists(SocialiteUser $user, string $driver): Redirect
{
$message = sprintf("An account with the email address '%s' already exists.", $user->email);

return $this->redirector()->to('login')->with('flash', [
return $this->redirector()->to(static::$userAlreadyExistsUrl)->with('flash', [
'bannerStyle' => 'danger',
'banner' => $message,
]);
Expand All @@ -47,7 +67,7 @@ public function unableToCreateUser(Exception $e, SocialiteUser $user, string $dr
{
report($e);

return $this->redirector()->to('login')->with('flash', [
return $this->redirector()->to(static::$unableToCreateUserUrl)->with('flash', [
'bannerStyle' => 'danger',
'banner' => 'There was a problem creating your account. Please try again.',
]);
Expand All @@ -62,7 +82,7 @@ public function userAuthenticated(Authenticatable $user, SocialiteUser $socialit

Session::regenerate();

return redirect('dashboard');
return redirect()->intended(static::$userAuthenticatedUrl);
}

/**
Expand Down

0 comments on commit 8f17546

Please sign in to comment.