42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import axios from 'axios';
|
|
|
|
export const loginRequest = (data: { login: string; password: string }) => {
|
|
return axios({
|
|
url: 'http://localhost:8002/login',
|
|
method: 'POST',
|
|
data
|
|
})
|
|
.then((r) => r.data as {access_token: string, refresh_token: string, token_type: string })
|
|
.catch((e) => {
|
|
throw e;
|
|
});
|
|
};
|
|
export const registerRequest = (data: { username: string; password: string, password_confirm: string }) => {
|
|
return axios({
|
|
url: 'http://localhost:8002/register',
|
|
method: 'POST',
|
|
data,
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
}
|
|
})
|
|
.then((r) => r.data as { access_token: string; refresh_token: string; token_type: string })
|
|
.catch((e) => {
|
|
throw e;
|
|
});
|
|
};
|
|
|
|
export const refreshRequest = (token: string) => {
|
|
return axios({
|
|
url: 'http://localhost:8002/refresh',
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
"Authorization": `Bearer ${token}`
|
|
}
|
|
})
|
|
.then((r) => r.data as {access_token:string})
|
|
.catch((e) => {
|
|
throw e;
|
|
});
|
|
} |