Refactored store
This commit is contained in:
@ -1,16 +1,19 @@
|
||||
import axios from "axios";
|
||||
import axiosInstance from "../http/axiosInstance";
|
||||
|
||||
export default class AuthService {
|
||||
static async hello() {
|
||||
return await axios.get(`${import.meta.env.VITE_API_AUTH_URL}/hello`)
|
||||
static async login(data: any) {
|
||||
return await axiosInstance.post(`/auth/login`, data, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static async getUsers() {
|
||||
return await axiosInstance.get(`/auth/user`)
|
||||
static async refreshToken(token: string) {
|
||||
return await axiosInstance.post(`/auth/refresh_token/${token}`)
|
||||
}
|
||||
|
||||
static async getCurrentUser(token: string){
|
||||
static async getCurrentUser(token: string) {
|
||||
return await axiosInstance.get(`/auth/get_current_user/${token}`)
|
||||
}
|
||||
}
|
@ -1,29 +1,32 @@
|
||||
// Data mockup
|
||||
let users =
|
||||
[
|
||||
{
|
||||
"email": "string",
|
||||
"login": "string",
|
||||
"phone": "string",
|
||||
"name": "string",
|
||||
"surname": "string",
|
||||
"is_active": true,
|
||||
"id": 0,
|
||||
"role_id": 2
|
||||
}
|
||||
]
|
||||
import axiosInstance from "../http/axiosInstance";
|
||||
import { UserCreds, UserData } from "../interfaces/auth";
|
||||
|
||||
export default class UserService {
|
||||
static async getUsers() {
|
||||
new Promise((resolve, reject) => {
|
||||
if (!users) {
|
||||
return setTimeout(
|
||||
() => reject(new Error('Users not found')),
|
||||
250
|
||||
)
|
||||
}
|
||||
static async createUser(data: any) {
|
||||
return await axiosInstance.post(`/auth/user`, data)
|
||||
}
|
||||
|
||||
setTimeout(() => resolve(users), 250)
|
||||
})
|
||||
static async getCurrentUser(token: string) {
|
||||
return await axiosInstance.get(`/auth/get_current_user/${token}`)
|
||||
}
|
||||
|
||||
static async getUsers() {
|
||||
return await axiosInstance.get(`/auth/user`)
|
||||
}
|
||||
|
||||
// static async deleteUser(id: number) {
|
||||
// return await axiosInstance.delete(`/auth/user/${id}`)
|
||||
// }
|
||||
|
||||
static async getUser(id: number) {
|
||||
return await axiosInstance.get(`/auth/user/${id}`)
|
||||
}
|
||||
|
||||
static async updatePassword(data: UserCreds) {
|
||||
return await axiosInstance.put(`/auth/user/password_change`, data)
|
||||
}
|
||||
|
||||
static async updateUser(data: UserData) {
|
||||
return await axiosInstance.put(`/auth/user`, data)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user