Skip to content

Commit

Permalink
feat: add "redirect" query string on sign-in redirect (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
batopa authored Mar 25, 2024
1 parent d126dbd commit b80f6f0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/runtime/middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ export default defineNuxtRouteMiddleware(async (to) => {

const { user, isLogged } = useBeditaAuth();

const redirectObject = {
path: config.public.bedita.auth.unauthenticatedRedirect,
query: { redirect: to.fullPath },
};

// if auth is required and user is not logged, redirect to login page
if (config.public.bedita.auth.required && !isLogged.value) {
return navigateTo(config.public.bedita.auth.unauthenticatedRedirect);
return navigateTo(redirectObject);
}

// check if user has required roles to access the route
Expand All @@ -40,7 +45,7 @@ export default defineNuxtRouteMiddleware(async (to) => {

// There are roles guard for this route, but user is not logged
if (!isLogged.value) {
return navigateTo(config.public.bedita.auth.unauthenticatedRedirect);
return navigateTo(redirectObject);
}

// if user has at least a role for the guard, then user is authorized
Expand Down

0 comments on commit b80f6f0

Please sign in to comment.