tethys.backend/app/validators/auth_validator.ts

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-03-14 19:25:27 +00:00
import { schema, rules } from '@adonisjs/validator';
import type { HttpContext } from '@adonisjs/core/http';
import { CustomMessages } from "@adonisjs/validator/types";
2023-03-03 15:54:28 +00:00
export default class AuthValidator {
2024-03-14 19:25:27 +00:00
constructor(protected ctx: HttpContext) {}
2023-03-03 15:54:28 +00:00
/*
* Define schema to validate the "shape", "type", "formatting" and "integrity" of data.
*
* For example:
* 1. The username must be of data type string. But then also, it should
* not contain special characters or numbers.
* ```
* schema.string({}, [ rules.alpha() ])
* ```
*
* 2. The email must be of data type string, formatted as a valid
* email. But also, not used by any other user.
* ```
* schema.string({}, [
* rules.email(),
* rules.unique({ table: 'users', column: 'email' }),
* ])
* ```
*/
public schema = schema.create({
email: schema.string({ trim: true }, [
rules.email(),
// rules.unique({ table: 'accounts', column: 'email' })
]),
password: schema.string({}, [rules.minLength(6)]),
});
2023-03-03 15:54:28 +00:00
/**
* Custom messages for validation failures. You can make use of dot notation `(.)`
* for targeting nested fields and array expressions `(*)` for targeting all
* children of an array. For example:
*
* {
* 'profile.username.required': 'Username is required',
* 'scores.*.number': 'Define scores as valid numbers'
* }
*
*/
public messages: CustomMessages = {};
2023-03-03 15:54:28 +00:00
}