mirror of https://github.com/wg-easy/wg-easy
committed by
GitHub
11 changed files with 37 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', () => { |
export const useAuthStore = defineStore('Auth', () => { |
||||
const { data: userData, refresh: update } = useFetch('/api/session', { |
const userData = useState<SharedPublicUser | null>('user-data', () => null); |
||||
method: 'get', |
|
||||
}); |
|
||||
|
|
||||
async function getSession() { |
async function getSession(event?: H3Event) { |
||||
|
const fetch = event?.$fetch || $fetch; |
||||
try { |
try { |
||||
const { data } = await useFetch('/api/session', { |
const data = await fetch('/api/session', { |
||||
method: 'get', |
method: 'get', |
||||
}); |
}); |
||||
return data.value; |
return data; |
||||
} catch { |
} catch { |
||||
return null; |
return null; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
|
async function update() { |
||||
|
const data = await getSession(); |
||||
|
userData.value = data; |
||||
|
} |
||||
|
|
||||
return { userData, update, getSession }; |
return { userData, update, getSession }; |
||||
}); |
}); |
||||
|
|||||
Loading…
Reference in new issue