SyntaxSquad/DADProject#9 feat: User info dysplayed in /users/
This commit is contained in:
@@ -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,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user