mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-20 11:41:38 +10:00
refactor(v4.0.0-alpha): beginning of a new era
This commit is contained in:
6
libs/dto/src/auth/forgot-password.ts
Normal file
6
libs/dto/src/auth/forgot-password.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { createZodDto } from "nestjs-zod/dto";
|
||||
import { z } from "nestjs-zod/z";
|
||||
|
||||
export const forgotPasswordSchema = z.object({ email: z.string().email() });
|
||||
|
||||
export class ForgotPasswordDto extends createZodDto(forgotPasswordSchema) {}
|
||||
8
libs/dto/src/auth/index.ts
Normal file
8
libs/dto/src/auth/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export * from "./forgot-password";
|
||||
export * from "./login";
|
||||
export * from "./message";
|
||||
export * from "./register";
|
||||
export * from "./reset-password";
|
||||
export * from "./response";
|
||||
export * from "./two-factor";
|
||||
export * from "./update-password";
|
||||
22
libs/dto/src/auth/login.ts
Normal file
22
libs/dto/src/auth/login.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { createZodDto } from "nestjs-zod/dto";
|
||||
import { z } from "nestjs-zod/z";
|
||||
|
||||
import { usernameSchema } from "../user";
|
||||
|
||||
export const loginSchema = z
|
||||
.object({
|
||||
identifier: z.string(),
|
||||
password: z.password().min(6),
|
||||
})
|
||||
.refine(
|
||||
(value) => {
|
||||
if (value.identifier.includes("@")) {
|
||||
return z.string().email().parse(value.identifier);
|
||||
} else {
|
||||
return usernameSchema.parse(value.identifier);
|
||||
}
|
||||
},
|
||||
{ message: "InvalidCredentials" },
|
||||
);
|
||||
|
||||
export class LoginDto extends createZodDto(loginSchema) {}
|
||||
6
libs/dto/src/auth/message.ts
Normal file
6
libs/dto/src/auth/message.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { createZodDto } from "nestjs-zod/dto";
|
||||
import { z } from "nestjs-zod/z";
|
||||
|
||||
export const messageSchema = z.object({ message: z.string() });
|
||||
|
||||
export class MessageDto extends createZodDto(messageSchema) {}
|
||||
10
libs/dto/src/auth/register.ts
Normal file
10
libs/dto/src/auth/register.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { createZodDto } from "nestjs-zod/dto";
|
||||
import { z } from "nestjs-zod/z";
|
||||
|
||||
import { userSchema } from "../user";
|
||||
|
||||
export const registerSchema = userSchema
|
||||
.pick({ name: true, email: true, username: true, language: true })
|
||||
.extend({ password: z.password().min(6) });
|
||||
|
||||
export class RegisterDto extends createZodDto(registerSchema) {}
|
||||
9
libs/dto/src/auth/reset-password.ts
Normal file
9
libs/dto/src/auth/reset-password.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { createZodDto } from "nestjs-zod/dto";
|
||||
import { z } from "nestjs-zod/z";
|
||||
|
||||
export const resetPasswordSchema = z.object({
|
||||
token: z.string(),
|
||||
password: z.password().min(6),
|
||||
});
|
||||
|
||||
export class ResetPasswordDto extends createZodDto(resetPasswordSchema) {}
|
||||
11
libs/dto/src/auth/response.ts
Normal file
11
libs/dto/src/auth/response.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { createZodDto } from "nestjs-zod/dto";
|
||||
import { z } from "nestjs-zod/z";
|
||||
|
||||
import { userSchema } from "../user";
|
||||
|
||||
export const authResponseSchema = z.object({
|
||||
status: z.enum(["authenticated", "2fa_required"]),
|
||||
user: userSchema,
|
||||
});
|
||||
|
||||
export class AuthResponseDto extends createZodDto(authResponseSchema) {}
|
||||
23
libs/dto/src/auth/two-factor.ts
Normal file
23
libs/dto/src/auth/two-factor.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { createZodDto } from "nestjs-zod/dto";
|
||||
import { z } from "nestjs-zod/z";
|
||||
|
||||
export const twoFactorSchema = z.object({
|
||||
code: z
|
||||
.string()
|
||||
.length(6)
|
||||
.regex(/^[0-9]+$/, { message: "code must be a 6 digit number" }),
|
||||
});
|
||||
|
||||
export class TwoFactorDto extends createZodDto(twoFactorSchema) {}
|
||||
|
||||
export const backupCodesSchema = z.object({
|
||||
backupCodes: z.array(z.string().length(10)),
|
||||
});
|
||||
|
||||
export class BackupCodesDto extends createZodDto(backupCodesSchema) {}
|
||||
|
||||
export const twoFactorBackupSchema = z.object({
|
||||
code: z.string().length(10),
|
||||
});
|
||||
|
||||
export class TwoFactorBackupDto extends createZodDto(twoFactorBackupSchema) {}
|
||||
8
libs/dto/src/auth/update-password.ts
Normal file
8
libs/dto/src/auth/update-password.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { createZodDto } from "nestjs-zod/dto";
|
||||
import { z } from "nestjs-zod/z";
|
||||
|
||||
export const updatePasswordSchema = z.object({
|
||||
password: z.string().min(6),
|
||||
});
|
||||
|
||||
export class UpdatePasswordDto extends createZodDto(updatePasswordSchema) {}
|
||||
Reference in New Issue
Block a user