fix: user info
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import type { Address } from './user/address'
|
||||
|
||||
export interface CustomerData {
|
||||
companyName: string
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { useFetchJson } from '@/composable/useFetchJson'
|
||||
import { useUserStore } from '../user'
|
||||
|
||||
export interface User {
|
||||
id: string
|
||||
@@ -41,6 +42,8 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
_isAuthenticated.value = readIsAuthenticatedCookie()
|
||||
}
|
||||
|
||||
// const auth = useAuthStore()
|
||||
// const userStore = useUserStore()
|
||||
async function login(email: string, password: string) {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
@@ -60,6 +63,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
|
||||
user.value = response.user
|
||||
_syncAuthState()
|
||||
// await userStore.getUser()
|
||||
|
||||
return true
|
||||
} catch (e: any) {
|
||||
@@ -99,7 +103,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
error.value = null
|
||||
try {
|
||||
const body: any = { first_name, last_name, email, password, confirm_password, lang: lang || 'en' }
|
||||
|
||||
|
||||
// Add company information if provided
|
||||
if (company_name) body.company_name = company_name
|
||||
if (company_email) body.company_email = company_email
|
||||
32
bo/src/stores/user.ts
Normal file
32
bo/src/stores/user.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { User } from '@/types/user'
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { useFetchJson } from '@/composable/useFetchJson'
|
||||
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const error = ref<string | null>(null)
|
||||
const user = ref<User | null>(null)
|
||||
|
||||
async function getUser() {
|
||||
error.value = null
|
||||
try {
|
||||
const data = await useFetchJson<User>(`/api/v1/restricted/customer`)
|
||||
console.log('getUser API response:', data)
|
||||
|
||||
const response: User = (data as any).items ?? data
|
||||
console.log('User response:', response)
|
||||
user.value = response
|
||||
|
||||
return response
|
||||
} catch (err: any) {
|
||||
error.value = err?.message ?? 'Unknown error'
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
error,
|
||||
user,
|
||||
getUser
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user