histories are a little messed, will change the logic in the future (techdebt)

This commit is contained in:
Edd
2025-12-30 01:49:39 +00:00
parent c456c9482f
commit 4f391e3638
12 changed files with 726 additions and 239 deletions
+8 -50
View File
@@ -1,58 +1,16 @@
import { defineStore } from 'pinia'
import axios from 'axios'
import { useAuthStore } from './auth'
import { inject } from 'vue'
export const useUserStore = defineStore('user', {
state: () => ({
user: null,
loading: false,
error: null
}),
export const useUserStore = defineStore('user', () => {
getters: {
currentUser: (state) => state.user
},
const API_BASE_URL = inject('apiBaseURL')
actions: {
async fetchUserProfile() {
const authStore = useAuthStore()
const token = authStore.getToken()
const getCoins = async () => {
return await axios.get(`${API_BASE_URL}/users/me/coins`)
}
if (!token) {
this.error = 'No authentication token found'
throw new Error('No authentication token found')
}
this.loading = true
this.error = null
try {
const response = await axios.get('/api/users/me', {
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/json'
}
})
this.user = response.data
return response.data
} catch (error) {
this.error = error.response?.data?.message || 'Failed to fetch user profile'
if (error.response?.status === 401) {
authStore.logout()
}
throw error
} finally {
this.loading = false
}
},
clearUser() {
this.user = null
this.error = null
this.loading = false
}
return {
getCoins,
}
})