Browse Source

fix: persist the redirection state in localstorage to maintain the value across redirection

pull/6616/head
Pranav C 1 year ago
parent
commit
2a88ff83f2
  1. 9
      packages/nc-gui/middleware/auth.global.ts

9
packages/nc-gui/middleware/auth.global.ts

@ -54,13 +54,18 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
/** if shared base allow without validating */
if (to.params.typeOrId === 'base') return
/** if auth is required or unspecified (same as required) and user is not signed in, redirect to signin page */
/** if auth is required or unspecified (same `as required) and user is not signed in, redirect to signin page */
if ((to.meta.requiresAuth || typeof to.meta.requiresAuth === 'undefined') && !state.signedIn.value) {
/** If this is the first usern navigate to signup page directly */
if (state.appInfo.value.firstUser) {
const query = to.fullPath !== '/' && to.fullPath.match(/^\/(?!\?)/) ? { continueAfterSignIn: to.fullPath } : {}
if (query.continueAfterSignIn) {
localStorage.setItem('continueAfterSignIn', query.continueAfterSignIn)
}
return navigateTo({
path: '/signup',
query: to.fullPath !== '/' && to.fullPath.match(/^\/(?!\?)/) ? { continueAfterSignIn: to.fullPath } : {},
query,
})
}

Loading…
Cancel
Save