Refactoring: Exported axios instance creation, now watching route param changes in EmployeesDetails.
This commit is contained in:
@@ -2,7 +2,8 @@ import { defineStore, storeToRefs } from 'pinia'
|
||||
import { useNotifications } from './notifications'
|
||||
import { getUnixTime } from 'date-fns'
|
||||
import { AxiosError } from 'axios'
|
||||
import axios from 'axios'
|
||||
import axios from '@/axios'
|
||||
import Axios from 'axios'
|
||||
|
||||
type AuthSuccResult = {
|
||||
user: string,
|
||||
@@ -38,7 +39,7 @@ export const useUser = defineStore({
|
||||
const notifications = useNotifications()
|
||||
|
||||
try {
|
||||
const response = await axios.post<AuthSuccResult>('http://localhost:3333/api/v1/login', {
|
||||
const response = await axios.post<AuthSuccResult>('login', {
|
||||
username: username,
|
||||
password: password
|
||||
})
|
||||
@@ -54,7 +55,7 @@ export const useUser = defineStore({
|
||||
|
||||
return true
|
||||
} catch(err : unknown) {
|
||||
if (axios.isAxiosError(err) && err.response && err.response.data){
|
||||
if (Axios.isAxiosError(err) && err.response && err.response.data){
|
||||
|
||||
const data = err.response.data
|
||||
|
||||
@@ -80,14 +81,11 @@ export const useUser = defineStore({
|
||||
const notifications = useNotifications()
|
||||
|
||||
try {
|
||||
const ai = axios.create({
|
||||
baseURL: 'http://localhost:3333/api/v1/',
|
||||
await axios.post('logout', '', {
|
||||
headers: {
|
||||
'Authorization': 'Bearer '+this.token
|
||||
'Authorization': 'Bearer '+useUser().token
|
||||
}
|
||||
|
||||
})
|
||||
await ai.post('/logout')
|
||||
|
||||
|
||||
notifications.add('success','Logged out successfully')
|
||||
|
||||
Reference in New Issue
Block a user