Browse Source

fix: after siginIn redirect to page in which user tried to access

pull/9294/head
Pranav C 3 months ago
parent
commit
c1eeb3e27d
  1. 14
      packages/nc-gui/pages/index.vue
  2. 31
      packages/nc-gui/plugins/redirect.ts

14
packages/nc-gui/pages/index.vue

@ -91,20 +91,6 @@ watch(
// immediate watch, because if route is changed during page transition
// It will error out nuxt
onMounted(() => {
if (route.value.query?.continueAfterSignIn) {
localStorage.removeItem('continueAfterSignIn')
return navigateTo(route.value.query.continueAfterSignIn as string)
} else {
const continueAfterSignIn = localStorage.getItem('continueAfterSignIn')
localStorage.removeItem('continueAfterSignIn')
if (continueAfterSignIn) {
return navigateTo({
path: continueAfterSignIn,
query: route.value.query,
})
}
}
handleRouteTypeIdChange().then(() => {
if (sharedBaseId.value) {
if (!isUIAllowed('baseDuplicate')) {

31
packages/nc-gui/plugins/redirect.ts

@ -0,0 +1,31 @@
// this plugin is used to redirect user to the page they were trying to access before they were redirected to the login page
export default defineNuxtPlugin(function (nuxtApp) {
const router = useRouter()
const route = router.currentRoute
watch(
() => (nuxtApp.$state as ReturnType<typeof useGlobal>)?.token?.value,
async (newToken, oldToken) => {
try {
if (newToken && newToken !== oldToken) {
if (route.value.query?.continueAfterSignIn) {
localStorage.removeItem('continueAfterSignIn')
await navigateTo(route.value.query.continueAfterSignIn as string)
} else {
const continueAfterSignIn = localStorage.getItem('continueAfterSignIn')
if (continueAfterSignIn) {
localStorage.removeItem('continueAfterSignIn')
await navigateTo({
path: continueAfterSignIn,
query: route.value.query,
})
}
}
}
} catch (e) {
console.error(e)
}
},
)
})
Loading…
Cancel
Save