This commit is contained in:
2025-06-05 20:00:58 +03:00
parent c8f3c9801f
commit 1c732e16dd
203 changed files with 9793 additions and 3960 deletions

View File

@@ -1,65 +0,0 @@
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { api } from 'boot/axios'
interface User {
id: string
email?: string
username: string
first_name?: string
last_name?: string
avatar?: string
}
export const useAuthStore = defineStore('auth', () => {
// State
const user = ref<User | null>(null)
const isInitialized = ref(false)
// Getters
const isAuthenticated = computed(() => !!user.value)
// Actions
const initialize = async () => {
try {
const { data } = await api.get('/customer/profile')
user.value = data
} catch (error) {
console.error(error)
user.value = null
} finally {
isInitialized.value = true
}
}
const loginWithCredentials = async (email: string, password: string) => {
// будет переделано на беке - нужно сменить урл
await api.post('/api/admin/customer/login', { email, password }, { withCredentials: true })
await initialize()
}
const loginWithTelegram = async (initData: string) => {
await api.post('/api/admin/customer/login', { initData }, { withCredentials: true })
await initialize()
}
const logout = async () => {
try {
await api.get('/customer/logout', {})
} finally {
user.value = null
// @ts-expect-ignore
// window.Telegram?.WebApp.close()
}
}
return {
user,
isAuthenticated,
isInitialized,
initialize,
loginWithCredentials,
loginWithTelegram,
logout
}
})