nuxt-start/stores/auth.ts
2025-01-02 20:56:21 +01:00

26 lines
585 B
TypeScript

import { defineStore } from 'pinia'
export const useAuthStore = defineStore({
id: 'AuthStore',
state: () => ({ user: null, rentals: null, rent: {} }),
actions: {
async getData() {
const token = useCookie('_auth')
if (token.value) {
const { data } = await useFetch('https://olcsoberauto.hu/rest/me',
{
headers: {
'auth-key': token.value
}
}
)
if (data.value?.user) {
this.user = data.value.user
this.rentals = data.value.rentals
}
}
}
}
})