Merge branch 'develop' into feature/frontend-gameboard-singleplayer

This commit is contained in:
2025-12-23 21:55:23 +00:00
9 changed files with 1040 additions and 486 deletions
+2
View File
@@ -7,6 +7,8 @@ export const useAuthStore = defineStore('auth', () => {
const DEFAULT_TIMEOUT = 5 * 60 * 1000
const REMEMBER_ME_TIMEOUT = 365 * 24 * 60 * 60 * 1000
const currentUser = ref(undefined)
const token = ref(localStorage.getItem('token') || null)
const tokenExpiry = ref(localStorage.getItem('tokenExpiry') ? parseInt(localStorage.getItem('tokenExpiry')) : null)
+58
View File
@@ -0,0 +1,58 @@
import { defineStore } from 'pinia'
import axios from 'axios'
import { useAuthStore } from './auth'
export const useUserStore = defineStore('user', {
state: () => ({
user: null,
loading: false,
error: null
}),
getters: {
currentUser: (state) => state.user
},
actions: {
async fetchUserProfile() {
const authStore = useAuthStore()
const token = authStore.getToken()
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
}
}
})