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 }, { 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 const globalState = { ...state, ...getters, ...actions } as UseGlobalReturn
/** provide a fresh state instance into nuxt app */ /** 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 */ /** State */
const initialState: StoredState = { const initialState: StoredState = {
token: null, token: null,
user: null,
lang: preferredLanguage, lang: preferredLanguage,
darkMode: prefersDarkMode, darkMode: prefersDarkMode,
feedbackForm: { feedbackForm: {
@ -102,6 +101,9 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
/** global error */ /** global error */
const error = ref() const error = ref()
/** our local user object */
const user = ref<User | null>(null)
return { return {
...toRefs(storage.value), ...toRefs(storage.value),
storage, storage,
@ -110,6 +112,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
timestamp, timestamp,
runningRequests, runningRequests,
error, error,
user,
appInfo, appInfo,
} }
} }

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

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

Loading…
Cancel
Save