|
|
@ -4,6 +4,7 @@ const isFullUrl = (url: string) => { |
|
|
|
|
|
|
|
|
|
|
|
// this plugin is used to redirect user to the page they were trying to access before they were redirected to the login page
|
|
|
|
// 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) { |
|
|
|
export default defineNuxtPlugin(function (nuxtApp) { |
|
|
|
|
|
|
|
const isTokenUpdatedTab = useState('isTokenUpdatedTab', () => false) |
|
|
|
const router = useRouter() |
|
|
|
const router = useRouter() |
|
|
|
|
|
|
|
|
|
|
|
const route = router.currentRoute |
|
|
|
const route = router.currentRoute |
|
|
@ -28,7 +29,10 @@ export default defineNuxtPlugin(function (nuxtApp) { |
|
|
|
() => token.value ?? (nuxtApp.$state as ReturnType<typeof useGlobal>)?.token?.value, |
|
|
|
() => token.value ?? (nuxtApp.$state as ReturnType<typeof useGlobal>)?.token?.value, |
|
|
|
async (newToken, oldToken) => { |
|
|
|
async (newToken, oldToken) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (newToken && newToken !== oldToken) { |
|
|
|
// if token updated redirect if one of the following condition matches,
|
|
|
|
|
|
|
|
// 1. `continueAfterSignIn` query param is present in the url
|
|
|
|
|
|
|
|
// 2. If signin happened in current tab which can be detected by `isTokenUpdatedTab` flag
|
|
|
|
|
|
|
|
if (newToken && newToken !== oldToken && (isTokenUpdatedTab.value || route.value.query?.continueAfterSignIn)) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (route.value.query?.continueAfterSignIn) { |
|
|
|
if (route.value.query?.continueAfterSignIn) { |
|
|
|
await navigateTo(route.value.query.continueAfterSignIn as string, { |
|
|
|
await navigateTo(route.value.query.continueAfterSignIn as string, { |
|
|
@ -44,6 +48,7 @@ export default defineNuxtPlugin(function (nuxtApp) { |
|
|
|
} |
|
|
|
} |
|
|
|
} finally { |
|
|
|
} finally { |
|
|
|
localStorage.removeItem('continueAfterSignIn') |
|
|
|
localStorage.removeItem('continueAfterSignIn') |
|
|
|
|
|
|
|
isTokenUpdatedTab.value = false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|