website/lib/schema/auth.ts

81 lines
2.6 KiB
TypeScript

import { z } from "zod";
// Register Schema
export const registerSchema = z
.object({
email: z.string().email("Invalid email address"),
first_name: z.string().min(1, "First name is required"),
last_name: z.string().min(1, "Last name is required"),
phone_number: z.string().optional(),
password: z.string().min(8, "Password must be at least 8 characters"),
password2: z.string().min(8, "Password confirmation is required"),
})
.refine((data) => data.password === data.password2, {
message: "Passwords do not match",
path: ["password2"],
});
export type RegisterInput = z.infer<typeof registerSchema>;
// Verify OTP Schema
export const verifyOtpSchema = z.object({
email: z.string().email("Invalid email address"),
otp: z.string().min(6, "OTP must be 6 digits").max(6, "OTP must be 6 digits"),
});
export type VerifyOtpInput = z.infer<typeof verifyOtpSchema>;
// Login Schema
export const loginSchema = z.object({
email: z.string().email("Invalid email address"),
password: z.string().min(1, "Password is required"),
});
export type LoginInput = z.infer<typeof loginSchema>;
// Resend OTP Schema
export const resendOtpSchema = z.object({
email: z.string().email("Invalid email address"),
context: z.enum(["registration", "password_reset"]).optional(),
});
export type ResendOtpInput = z.infer<typeof resendOtpSchema>;
// Forgot Password Schema
export const forgotPasswordSchema = z.object({
email: z.string().email("Invalid email address"),
});
export type ForgotPasswordInput = z.infer<typeof forgotPasswordSchema>;
// Verify Password Reset OTP Schema
export const verifyPasswordResetOtpSchema = z.object({
email: z.string().email("Invalid email address"),
otp: z.string().min(6, "OTP must be 6 digits").max(6, "OTP must be 6 digits"),
});
export type VerifyPasswordResetOtpInput = z.infer<typeof verifyPasswordResetOtpSchema>;
// Reset Password Schema
export const resetPasswordSchema = z
.object({
email: z.string().email("Invalid email address"),
otp: z.string().min(6, "OTP must be 6 digits").max(6, "OTP must be 6 digits"),
new_password: z.string().min(8, "Password must be at least 8 characters"),
confirm_password: z.string().min(8, "Password confirmation is required"),
})
.refine((data) => data.new_password === data.confirm_password, {
message: "Passwords do not match",
path: ["confirm_password"],
});
export type ResetPasswordInput = z.infer<typeof resetPasswordSchema>;
// Token Refresh Schema
export const tokenRefreshSchema = z.object({
refresh: z.string().min(1, "Refresh token is required"),
});
export type TokenRefreshInput = z.infer<typeof tokenRefreshSchema>;