mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: update front
This commit is contained in:
31
assets/utils/api.ts
Normal file
31
assets/utils/api.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import axios, {AxiosRequestConfig, AxiosResponse} from "axios";
|
||||
|
||||
|
||||
export async function login(email: string, password: string): Promise<boolean> {
|
||||
const response = await request({
|
||||
method: 'POST',
|
||||
url: 'login',
|
||||
data: {email, password}
|
||||
})
|
||||
return response.status === 200
|
||||
}
|
||||
|
||||
export async function getUser(): Promise<object> {
|
||||
const response = await request({
|
||||
url: 'me'
|
||||
})
|
||||
return response.data
|
||||
}
|
||||
|
||||
|
||||
async function request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig): Promise<R> {
|
||||
const axiosConfig: AxiosRequestConfig = {
|
||||
...config,
|
||||
baseURL: '/api',
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
Accept: 'application/ld+json'
|
||||
}
|
||||
}
|
||||
return await axios.request<T, any, D>(axiosConfig)
|
||||
}
|
||||
Reference in New Issue
Block a user