mirror of https://github.com/nocodb/nocodb
Browse Source
# What's changed? * instead of using the useUser composable, we inject a global state containing user and tokenpull/2716/head
Braks
2 years ago
committed by
Pranav C
10 changed files with 58 additions and 97 deletions
@ -1,16 +0,0 @@
|
||||
import type { Api } from 'nocodb-sdk' |
||||
import { useNuxtApp } from '#app' |
||||
|
||||
export const useUser = () => { |
||||
const { $api, $state } = useNuxtApp() |
||||
|
||||
const getUser = async (...args: Parameters<Api<any>['auth']['me']>) => { |
||||
$state.user = await $api.auth.me(...args) |
||||
} |
||||
|
||||
const setToken = (token?: string) => { |
||||
$state.token = token |
||||
} |
||||
|
||||
return { user: $state.user, setToken, getUser } |
||||
} |
@ -1,7 +1,12 @@
|
||||
import { defineNuxtPlugin } from '#app' |
||||
import { defineNuxtPlugin } from 'nuxt3/app' |
||||
import { useGlobalState } from '~/composables/useGlobalState' |
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => { |
||||
const createGlobalState = useGlobalState() |
||||
nuxtApp.provide('state', createGlobalState()) |
||||
const globalState = createGlobalState() |
||||
|
||||
// set initial app language to the first preferred language (found in state)
|
||||
;(nuxtApp.vueApp as any).i18n.global.locale.value = globalState.value.lang |
||||
|
||||
nuxtApp.provide('state', globalState) |
||||
}) |
||||
|
Loading…
Reference in new issue