Browse Source

refactor(gui-v2): change token and user type to accept null value

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
pull/2716/head
Braks 2 years ago committed by Pranav C
parent
commit
4aae2d8356
  1. 6
      packages/nc-gui-v2/composables/useGlobalState.ts
  2. 10
      packages/nc-gui-v2/lib/types.ts
  3. 4
      packages/nc-gui-v2/pages/signin.vue

6
packages/nc-gui-v2/composables/useGlobalState.ts

@ -11,7 +11,7 @@ export const useGlobalState = (): GlobalState => {
const preferredLanguages = $(usePreferredLanguages())
const darkMode = $(usePreferredDark())
const initialState = { token: undefined, user: undefined, lang: preferredLanguages[0] || 'en', darkMode }
const initialState = { token: null, user: null, lang: preferredLanguages[0] || 'en', darkMode }
const storage = useStorage<State>(storageKey, initialState)
@ -20,8 +20,8 @@ export const useGlobalState = (): GlobalState => {
// actions
function signOut() {
storage.value.token = undefined
storage.value.user = undefined
storage.value.token = null
storage.value.user = null
}
return { ...toRefs(storage.value), signedIn, signOut }

10
packages/nc-gui-v2/lib/types.ts

@ -1,10 +1,12 @@
import type { ComputedRef, ToRefs } from 'vue'
export interface State {
token?: string
user?: {
email?: string
export interface User {
email: string
}
export interface State {
token: string | null
user: User | null
lang: string
darkMode: boolean
}

4
packages/nc-gui-v2/pages/signin.vue

@ -51,8 +51,8 @@ const signIn = async () => {
try {
const { token } = await $api.auth.signin(form)
$state.token = token
$state.user = { email: form.email }
$state.token.value = token!
$state.user.value = { email: form.email }
await navigateTo('/projects')
} catch (e: any) {

Loading…
Cancel
Save