SyntaxSquad/DADProject#9 feat: User info dysplayed in /users/

This commit is contained in:
2025-12-18 21:04:49 +00:00
parent 94fdbd568c
commit d1dd2c00f6
7 changed files with 305 additions and 93 deletions
+12
View File
@@ -1,3 +1,4 @@
// src/stores/api.js
import { defineStore } from 'pinia'
import axios from 'axios'
import { inject, ref } from 'vue'
@@ -21,7 +22,10 @@ export const useAPIStore = defineStore('api', () => {
const response = await axios.post(`${API_BASE_URL}/login`, credentials)
token.value = response.data.token
axios.defaults.headers.common['Authorization'] = `Bearer ${token.value}`
return response
}
const postLogout = async () => {
await axios.post(`${API_BASE_URL}/logout`)
token.value = undefined
@@ -53,11 +57,19 @@ export const useAPIStore = defineStore('api', () => {
return axios.get(`${API_BASE_URL}/games?${queryParams}`)
}
const initToken = (storedToken) => {
if (storedToken) {
token.value = storedToken
axios.defaults.headers.common['Authorization'] = `Bearer ${storedToken}`
}
}
return {
postLogin,
postLogout,
getAuthUser,
getGames,
gameQueryParameters,
initToken,
}
})