Initial Commit

This commit is contained in:
2026-06-06 13:23:33 +01:00
commit 1a0d45dd67
58 changed files with 5268 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
import { create } from 'zustand'
import api from '../utils/api'
export const useAuthStore = create((set) => ({
token: localStorage.getItem('token'),
user: null,
isLoading: false,
login: async (username, password) => {
set({ isLoading: true })
try {
const params = new URLSearchParams()
params.append('username', username)
params.append('password', password)
const { data } = await api.post('/auth/token', params, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
})
localStorage.setItem('token', data.access_token)
set({ token: data.access_token, user: data, isLoading: false })
return true
} catch (e) {
set({ isLoading: false })
throw e
}
},
logout: () => {
localStorage.removeItem('token')
set({ token: null, user: null })
},
fetchUser: async () => {
try {
const { data } = await api.get('/auth/me')
set({ user: data })
} catch {
set({ token: null, user: null })
localStorage.removeItem('token')
}
},
}))