mirror of https://github.com/wg-easy/wg-easy
11 changed files with 41 additions and 30 deletions
@ -1,18 +1,25 @@ |
|||
import type { H3Event } from 'h3'; |
|||
import type { SharedPublicUser } from '~~/shared/utils/permissions'; |
|||
|
|||
export const useAuthStore = defineStore('Auth', () => { |
|||
const { data: userData, refresh: update } = useFetch('/api/session', { |
|||
method: 'get', |
|||
}); |
|||
const userData = useState<SharedPublicUser | null>('user-data', () => null); |
|||
|
|||
async function getSession() { |
|||
async function getSession(event?: H3Event) { |
|||
const fetch = event?.$fetch || $fetch; |
|||
try { |
|||
const { data } = await useFetch('/api/session', { |
|||
const data = await fetch('/api/session', { |
|||
method: 'get', |
|||
}); |
|||
return data.value; |
|||
return data; |
|||
} catch { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
async function update() { |
|||
const data = await getSession(); |
|||
userData.value = data; |
|||
} |
|||
|
|||
return { userData, update, getSession }; |
|||
}); |
|||
|
|||
Loading…
Reference in new issue