Browse Source

Merge pull request #3701 from nocodb/fix/reset-roles

pull/3712/head
Braks 2 years ago committed by GitHub
parent
commit
2dc7139855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      packages/nc-gui/composables/useGlobal/index.ts
  2. 5
      packages/nc-gui/composables/useGlobal/state.ts
  3. 2
      packages/nc-gui/composables/useGlobal/types.ts

16
packages/nc-gui/composables/useGlobal/index.ts

@ -62,6 +62,22 @@ export const useGlobal = (): UseGlobalReturn => {
{ immediate: true },
)
watch(
state.jwtPayload,
(nextPayload) => {
if (nextPayload) {
state.user.value = {
id: nextPayload.id,
email: nextPayload.email,
firstname: nextPayload.firstname,
lastname: nextPayload.lastname,
roles: nextPayload.roles,
}
}
},
{ immediate: true },
)
const globalState = { ...state, ...getters, ...actions } as UseGlobalReturn
/** provide a fresh state instance into nuxt app */

5
packages/nc-gui/composables/useGlobal/state.ts

@ -49,7 +49,6 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
/** State */
const initialState: StoredState = {
token: null,
user: null,
lang: preferredLanguage,
darkMode: prefersDarkMode,
feedbackForm: {
@ -102,6 +101,9 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
/** global error */
const error = ref()
/** our local user object */
const user = ref<User | null>(null)
return {
...toRefs(storage.value),
storage,
@ -110,6 +112,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
timestamp,
runningRequests,
error,
user,
appInfo,
}
}

2
packages/nc-gui/composables/useGlobal/types.ts

@ -29,7 +29,6 @@ export interface AppInfo {
export interface StoredState {
token: string | null
user: User | null
lang: keyof typeof Language
darkMode: boolean
feedbackForm: FeedbackForm
@ -43,6 +42,7 @@ export interface StoredState {
export type State = ToRefs<Omit<StoredState, 'token'>> & {
storage: Ref<StoredState>
user: Ref<User | null>
token: WritableComputedRef<StoredState['token']>
jwtPayload: ComputedRef<(JwtPayload & User) | null>
timestamp: Ref<number>

Loading…
Cancel
Save