feat: implement login functionality with error handling and session management

This commit is contained in:
2026-07-13 10:40:40 +05:30
parent e0167caf85
commit 36302ff564
5 changed files with 162 additions and 16 deletions
+6 -13
View File
@@ -15,21 +15,14 @@ export const emailSchema = z.preprocess(
z.string().min(1, "Email is required").email("Enter a valid email")
)
// Login schema (email + password) for reuse across the app
// Login schema (email + password) for reuse across the app.
// Password strength is intentionally NOT re-validated here: an existing
// account's password may predate current complexity rules, and only the
// server can judge whether credentials are actually correct. Complexity
// rules belong on registration/reset-password, not on login.
export const loginSchema = z.object({
email: emailSchema,
password: requiredString("Password is required")
.refine((val) => val.length >= 8, { message: "Password must be at least 8 characters" })
.refine((val) => /[A-Z]/.test(val), {
message: "Password must contain at least one uppercase letter",
})
.refine((val) => /[a-z]/.test(val), {
message: "Password must contain at least one lowercase letter",
})
.refine((val) => /[0-9]/.test(val), { message: "Password must contain at least one number" })
.refine((val) => /[!@#$%^&*(),.?":{}|<>\[\]\\/`~;'+=-]/.test(val), {
message: "Password must contain at least one special character",
}),
password: requiredString("Password is required"),
})
export type LoginValues = z.infer<typeof loginSchema>