Skip to content

Commit 55833ac

Browse files
authored
Merge pull request #3 from devforth/open-signup
fix: Improve OAuth authentication error handling and user experience
2 parents 80160a7 + a455755 commit 55833ac

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

custom/OAuthCallback.vue

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
<template>
22
<div class="flex items-center justify-center min-h-screen">
3-
<Spinner />
3+
<div v-if="error" class="py-8 px-4 mx-auto max-w-screen-xl lg:py-16 lg:px-6">
4+
<div class="mx-auto max-w-screen-sm text-center">
5+
<h1 class="mb-4 text-7xl tracking-tight font-extrabold lg:text-9xl text-lightPrimary dark:text-darkPrimary">
6+
Oops!
7+
</h1>
8+
<p class="mb-4 text-3xl tracking-tight font-bold text-gray-900 md:text-4xl dark:text-white">
9+
Authentication Failed
10+
</p>
11+
<p class="mb-4 text-lg font-light text-gray-500 dark:text-gray-400">
12+
{{ error }}
13+
</p>
14+
<div class="flex justify-center">
15+
<LinkButton to="/login">Back to Login</LinkButton>
16+
</div>
17+
</div>
18+
</div>
19+
<Spinner v-else />
420
</div>
521
</template>
622

723
<script setup>
8-
import { onMounted } from 'vue';
24+
import { onMounted, ref } from 'vue';
925
import { useUserStore } from '@/stores/user';
1026
import { useRouter, useRoute } from 'vue-router';
1127
import { callAdminForthApi } from '@/utils';
12-
import { Spinner } from '@/afcl';
28+
import { Spinner, LinkButton } from '@/afcl';
1329
1430
const router = useRouter();
1531
const userStore = useUserStore();
1632
const route = useRoute();
33+
const error = ref(null);
1734
1835
onMounted(async () => {
1936
const urlParams = new URLSearchParams(window.location.search);
@@ -31,18 +48,16 @@ onMounted(async () => {
3148
path: `/oauth/callback?code=${encodedCode}&state=${encodedState}&redirect_uri=${redirectUri}`,
3249
method: 'GET',
3350
});
51+
3452
if (response.allowedLogin) {
3553
await userStore.finishLogin();
3654
} else if (response.redirectTo) {
3755
router.push(response.redirectTo);
3856
} else if (response.error) {
39-
router.push({
40-
name: 'login',
41-
query: { error: response.error }
42-
});
57+
error.value = response.error;
4358
}
4459
} else {
45-
router.push({ name: 'login' });
60+
error.value = 'Invalid authentication request. Missing required parameters.';
4661
}
4762
});
4863
</script>

index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ export default class OAuthPlugin extends AdminForthPlugin {
182182
// Check if open signup is enabled
183183
if (!this.options.openSignup?.enabled) {
184184
return {
185-
error: 'User not found and open signup is disabled',
186-
redirectTo: '/login'
185+
error: 'User with your email is not registered in system and signup is not allowed. Please contact your administrator to get access to the system'
187186
};
188187
}
189188

@@ -211,8 +210,7 @@ export default class OAuthPlugin extends AdminForthPlugin {
211210
} catch (error) {
212211
console.error('OAuth authentication error:', error);
213212
return {
214-
error: 'Authentication failed',
215-
redirectTo: '/login'
213+
error: `Authentication failed: ${error}`
216214
};
217215
}
218216
}

0 commit comments

Comments
 (0)