I am using Nuxt 3 and Pinia, after refreshing the page it logs me out, but after removing part of the code from the auth.js file:
// If the user is not logged in, redirect to the login page
if (!user.value) {
return router.push(`/admin/sprawy-w-toku/`);
}
// If the user is not logged in, redirect to the login page
const adminUserIds = [
];
// Array of user IDs who have access to the admin panel
if (!adminUserIds.includes(user.value.id)) {
return router.push('/'); // Redirect to the page when the user does not have permissions
}
, it no longer logs me out.
My file auth.js:
// middleware/adminAuth.js
export default defineNuxtRouteMiddleware(async (to, from) => {
const { $supabase } = useNuxtApp();
const user = useSupabaseUser();
const router = useRouter();
// If the user is not logged in, redirect to the login page
if (!user.value) {
return router.push(`/admin/sprawy-w-toku/`);
}
// Array of user IDs who have access to the admin panel
const adminUserIds = [
];
// Check if the logged-in user's ID is on the list of admins
if (!adminUserIds.includes(user.value.id)) {
return router.push('/'); // Redirect to the page when the user does not have permissions
}
});
I tried removing parts of the code, but I wasn’t able to find a solution.
New contributor
Bartek Misiak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.