Files
tier-maker/frontend/src/stores/auth.js

36 lines
750 B
JavaScript

import { defineStore } from 'pinia'
import { api } from '../lib/api'
export const useAuthStore = defineStore('auth', {
state: () => ({
user: null,
status: 'idle',
}),
actions: {
async refresh() {
this.status = 'loading'
try {
const data = await api.me()
this.user = data.user
} finally {
this.status = 'idle'
}
},
async signup(email, password) {
const user = await api.signup({ email, password })
this.user = user
return user
},
async login(email, password) {
const user = await api.login({ email, password })
this.user = user
return user
},
async logout() {
await api.logout()
this.user = null
},
},
})