Redirect to index on auth-failure if user not logged in (fixes #192)
Change-Id: Ifc38d975542b6b30fa2b4bae6d5753d80be4e642
diff --git a/lib/Kalamar/Plugin/Auth.pm b/lib/Kalamar/Plugin/Auth.pm
index 75d231f..80422ab 100644
--- a/lib/Kalamar/Plugin/Auth.pm
+++ b/lib/Kalamar/Plugin/Auth.pm
@@ -1152,7 +1152,9 @@
else {
$c->notify(error => $c->loc('Auth_paramError'));
};
- return $c->redirect_to('oauth-settings');
+
+ # If logged in, go to oauth settings - otherwise to index
+ return $c->redirect_to($c->auth->token ? 'oauth-settings' : 'index');
};
foreach (qw!scope client_id state redirect_uri!) {
@@ -1213,7 +1215,9 @@
# Redirect unknown
else {
$c->notify(error => 'redirect_uri not set');
- return $c->redirect_to('oauth-settings');
+
+ # If logged in, go to oauth settings - otherwise to index
+ return $c->redirect_to($c->auth->token ? 'oauth-settings' : 'index');
};
# No userinfo allowed
@@ -1246,7 +1250,9 @@
sub {
my $error = shift;
$c->notify(error => $error);
- return $c->redirect_to('oauth-settings');
+
+ # If logged in, go to oauth settings - otherwise to index
+ return $c->redirect_to($c->auth->token ? 'oauth-settings' : 'index');
}
);
}
@@ -1275,7 +1281,8 @@
# Render with error
if ($v->has_error) {
- my $url = $c->url_for('oauth-settings');
+ # If logged in, go to oauth settings - otherwise to index
+ my $url = $c->url_for($c->auth->token ? 'oauth-settings' : 'index');
if ($v->has_error('client_id')) {
$url->query([error_description => $c->loc('Auth_clientIDFail')]);
@@ -1360,7 +1367,9 @@
# Do not redirect!
else {
$c->notify(error => $err_msg);
- $url = $c->url_for('oauth-settings');
+
+ # If logged in, go to oauth settings - otherwise to index
+ $url = $c->url_for($c->auth->token ? 'oauth-settings' : 'index');
};
return Mojo::Promise->resolve($url);