import { celebrate , SchemaOptions , Modes , Segments , Joi } from "celebrate" ; import { PWD_RESET_TOKEN_BYTES } from "./config" ; export const validate = ( schema ) => celebrate ( schema , { abortEarly : false , } , { mode : Modes . FULL , } ) ; const email = Joi . string ( ) . email ( ) . required ( ) ; const password = Joi . string ( ) . max ( 256 ) . required ( ) ; export const loginSchema = { [ Segments . BODY ] : Joi . object ( ) . keys ( { email , password , } ) , } ; export const registerSchema = { [ Segments . BODY ] : Joi . object ( ) . keys ( { email , password , name : Joi . string ( ) . max ( 256 ) . required ( ) , } ) , } ; const id = Joi . number ( ) . positive ( ) . max ( 2 ** 31 - 1 ) . required ( ) ; export const verifyEmailSchema = { [ Segments . QUERY ] : { id , expires : Joi . date ( ) . timestamp ( ) . raw ( ) . required ( ) , signature : Joi . string ( ) . length ( 64 ) . required ( ) , } , } ; export const resendEmailSchema = { [ Segments . BODY ] : Joi . object ( ) . keys ( { email , } ) , } ; export const sendResetSchema = { [ Segments . BODY ] : Joi . object ( ) . keys ( { email , } ) , } ; export const resetPasswordSchema = { [ Segments . QUERY ] : { id , token : Joi . string ( ) . length ( PWD_RESET_TOKEN_BYTES * 2 ) . required ( ) , } , [ Segments . BODY ] : Joi . object ( ) . keys ( { password , } ) , } ; export const confirmPasswordSchema = { [ Segments . BODY ] : Joi . object ( ) . keys ( { password , } ) , } ;