Frontend validation

This commit is contained in:
2022-08-25 14:16:29 +02:00
parent 65464e762a
commit 23ba777e5a
9 changed files with 40 additions and 29 deletions

View File

@@ -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);

View File

@@ -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,

View File

@@ -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>