Frontend validation
This commit is contained in:
@@ -27,4 +27,4 @@ export const auth_signup = (
|
||||
export const refresh_token = (
|
||||
token: string
|
||||
): Promise<Responses.Auth.RefreshResponse | Responses.ErrorResponse> =>
|
||||
post_token('/api/auth/refresh', '', token);
|
||||
post_token('/api/auth/refresh', {}, token);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import axios from 'axios';
|
||||
import { Requests, Responses } from 'dto';
|
||||
export { Requests, Responses };
|
||||
import { validateSync } from 'class-validator';
|
||||
|
||||
export const post = <T extends Requests.BaseRequest>(url: string, data: T) =>
|
||||
axios
|
||||
@@ -9,12 +11,17 @@ export const post = <T extends Requests.BaseRequest>(url: string, data: T) =>
|
||||
.then((res) => res.data)
|
||||
.catch((err) => err.response.data);
|
||||
|
||||
export const post_token = <T extends Requests.BaseRequest>(
|
||||
export function post_token<T extends Requests.BaseRequest>(
|
||||
url: string,
|
||||
data: T,
|
||||
token: string
|
||||
) =>
|
||||
axios
|
||||
) {
|
||||
const errors = validateSync(data);
|
||||
if (errors.length > 0) {
|
||||
console.error('Validation failed, errors: ', errors);
|
||||
throw new Error('Validation failed');
|
||||
}
|
||||
return axios
|
||||
.post(url, data, {
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + token,
|
||||
@@ -23,6 +30,7 @@ export const post_token = <T extends Requests.BaseRequest>(
|
||||
})
|
||||
.then((res) => res.data)
|
||||
.catch((err) => err.response.data);
|
||||
}
|
||||
|
||||
export const post_token_form = (
|
||||
url: string,
|
||||
|
||||
@@ -13,7 +13,7 @@ router.replace({ path: '/' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-link to="home">Click here to go home</router-link>
|
||||
<router-link to="/">Click here to go home</router-link>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
|
||||
Reference in New Issue
Block a user