Skip to content

fix: Improve OAuth authentication error handling and user experience #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions custom/OAuthCallback.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
<template>
<div class="flex items-center justify-center min-h-screen">
<Spinner />
<div v-if="error" class="py-8 px-4 mx-auto max-w-screen-xl lg:py-16 lg:px-6">
<div class="mx-auto max-w-screen-sm text-center">
<h1 class="mb-4 text-7xl tracking-tight font-extrabold lg:text-9xl text-lightPrimary dark:text-darkPrimary">
Oops!
</h1>
<p class="mb-4 text-3xl tracking-tight font-bold text-gray-900 md:text-4xl dark:text-white">
Authentication Failed
</p>
<p class="mb-4 text-lg font-light text-gray-500 dark:text-gray-400">
{{ error }}
</p>
<div class="flex justify-center">
<LinkButton to="/login">Back to Login</LinkButton>
</div>
</div>
</div>
<Spinner v-else />
</div>
</template>

<script setup>
import { onMounted } from 'vue';
import { onMounted, ref } from 'vue';
import { useUserStore } from '@/stores/user';
import { useRouter, useRoute } from 'vue-router';
import { callAdminForthApi } from '@/utils';
import { Spinner } from '@/afcl';
import { Spinner, LinkButton } from '@/afcl';

const router = useRouter();
const userStore = useUserStore();
const route = useRoute();
const error = ref(null);

onMounted(async () => {
const urlParams = new URLSearchParams(window.location.search);
Expand All @@ -31,18 +48,16 @@ onMounted(async () => {
path: `/oauth/callback?code=${encodedCode}&state=${encodedState}&redirect_uri=${redirectUri}`,
method: 'GET',
});

if (response.allowedLogin) {
await userStore.finishLogin();
} else if (response.redirectTo) {
router.push(response.redirectTo);
} else if (response.error) {
router.push({
name: 'login',
query: { error: response.error }
});
error.value = response.error;
}
} else {
router.push({ name: 'login' });
error.value = 'Invalid authentication request. Missing required parameters.';
}
});
</script>
6 changes: 2 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ export default class OAuthPlugin extends AdminForthPlugin {
// Check if open signup is enabled
if (!this.options.openSignup?.enabled) {
return {
error: 'User not found and open signup is disabled',
redirectTo: '/login'
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'
};
}

Expand Down Expand Up @@ -211,8 +210,7 @@ export default class OAuthPlugin extends AdminForthPlugin {
} catch (error) {
console.error('OAuth authentication error:', error);
return {
error: 'Authentication failed',
redirectTo: '/login'
error: `Authentication failed: ${error}`
};
}
}
Expand Down