Browse Source

Merge pull request #9540 from nocodb/nc-fix/9501-redirection-issue

Nc fix/9501 redirection issue
pull/9544/head
Pranav C 3 months ago committed by GitHub
parent
commit
138db24eca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      packages/nc-gui/composables/useGlobal/actions.ts
  2. 7
      packages/nc-gui/plugins/redirect.ts

3
packages/nc-gui/composables/useGlobal/actions.ts

@ -3,6 +3,8 @@ import type { Actions, AppInfo, State } from './types'
import type { NcProjectType } from '#imports'
export function useGlobalActions(state: State): Actions {
const isTokenUpdatedTab = useState('isTokenUpdatedTab', () => false)
const setIsMobileMode = (isMobileMode: boolean) => {
state.isMobileMode.value = isMobileMode
}
@ -44,6 +46,7 @@ export function useGlobalActions(state: State): Actions {
* keepProps - is for keeping any existing role info if user id is same as previous user
* */
const signIn: Actions['signIn'] = async (newToken, keepProps = false) => {
isTokenUpdatedTab.value = true
state.token.value = newToken
if (state.jwtPayload.value) {

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

@ -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
export default defineNuxtPlugin(function (nuxtApp) {
const isTokenUpdatedTab = useState('isTokenUpdatedTab', () => false)
const router = useRouter()
const route = router.currentRoute
@ -28,7 +29,10 @@ export default defineNuxtPlugin(function (nuxtApp) {
() => token.value ?? (nuxtApp.$state as ReturnType<typeof useGlobal>)?.token?.value,
async (newToken, oldToken) => {
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 {
if (route.value.query?.continueAfterSignIn) {
await navigateTo(route.value.query.continueAfterSignIn as string, {
@ -44,6 +48,7 @@ export default defineNuxtPlugin(function (nuxtApp) {
}
} finally {
localStorage.removeItem('continueAfterSignIn')
isTokenUpdatedTab.value = false
}
}
} catch (e) {

Loading…
Cancel
Save