save work
Browse files- app/api/auth/register/route.ts +1 -1
- app/api/auth/verify/route.ts +2 -2
- app/api/shop/template/route.ts +2 -0
- app/api/upload/route.ts +2 -1
- app/api/user/password/route.ts +2 -2
- lib/api/audit.ts +3 -1
- lib/validations.ts +1 -1
app/api/auth/register/route.ts
CHANGED
|
@@ -30,7 +30,7 @@ const passwordSchema = z
|
|
| 30 |
.regex(/[0-9]/, "Mật khẩu phải chứa ít nhất 1 số");
|
| 31 |
|
| 32 |
const registerSchema = z.object({
|
| 33 |
-
email: z.
|
| 34 |
password: passwordSchema,
|
| 35 |
name: z.string().min(2, "Tên phải chứa ít nhất 2 ký tự").optional(),
|
| 36 |
role: z.enum(["CUSTOMER", "VENDOR"]).default("CUSTOMER"),
|
|
|
|
| 30 |
.regex(/[0-9]/, "Mật khẩu phải chứa ít nhất 1 số");
|
| 31 |
|
| 32 |
const registerSchema = z.object({
|
| 33 |
+
email: z.email("Địa chỉ email không hợp lệ"),
|
| 34 |
password: passwordSchema,
|
| 35 |
name: z.string().min(2, "Tên phải chứa ít nhất 2 ký tự").optional(),
|
| 36 |
role: z.enum(["CUSTOMER", "VENDOR"]).default("CUSTOMER"),
|
app/api/auth/verify/route.ts
CHANGED
|
@@ -17,12 +17,12 @@ import {
|
|
| 17 |
import { prisma } from "@/lib/prisma";
|
| 18 |
|
| 19 |
const verifySchema = z.object({
|
| 20 |
-
email: z.
|
| 21 |
token: z.string().min(1),
|
| 22 |
});
|
| 23 |
|
| 24 |
const resendSchema = z.object({
|
| 25 |
-
email: z.
|
| 26 |
});
|
| 27 |
|
| 28 |
/**
|
|
|
|
| 17 |
import { prisma } from "@/lib/prisma";
|
| 18 |
|
| 19 |
const verifySchema = z.object({
|
| 20 |
+
email: z.email(),
|
| 21 |
token: z.string().min(1),
|
| 22 |
});
|
| 23 |
|
| 24 |
const resendSchema = z.object({
|
| 25 |
+
email: z.email(),
|
| 26 |
});
|
| 27 |
|
| 28 |
/**
|
app/api/shop/template/route.ts
CHANGED
|
@@ -16,6 +16,8 @@ export async function GET(req: NextRequest) {
|
|
| 16 |
try {
|
| 17 |
const auth = await getAuthenticatedVendor();
|
| 18 |
|
|
|
|
|
|
|
| 19 |
if (isErrorResult(auth)) {
|
| 20 |
return errorResponse(auth.error, auth.status);
|
| 21 |
}
|
|
|
|
| 16 |
try {
|
| 17 |
const auth = await getAuthenticatedVendor();
|
| 18 |
|
| 19 |
+
// process.stdout.write(`test: ${req}`);
|
| 20 |
+
|
| 21 |
if (isErrorResult(auth)) {
|
| 22 |
return errorResponse(auth.error, auth.status);
|
| 23 |
}
|
app/api/upload/route.ts
CHANGED
|
@@ -57,7 +57,8 @@ export async function POST(request: NextRequest) {
|
|
| 57 |
height: result.height,
|
| 58 |
});
|
| 59 |
} catch (error: any) {
|
| 60 |
-
console.error("UPLOAD ERROR", error);
|
|
|
|
| 61 |
|
| 62 |
return NextResponse.json(
|
| 63 |
{ error: error.message || "Tải lên thất bại" },
|
|
|
|
| 57 |
height: result.height,
|
| 58 |
});
|
| 59 |
} catch (error: any) {
|
| 60 |
+
// console.error("UPLOAD ERROR", error);
|
| 61 |
+
process.stdout.write(`UPLOAD ERROR: ${error.message}\n`);
|
| 62 |
|
| 63 |
return NextResponse.json(
|
| 64 |
{ error: error.message || "Tải lên thất bại" },
|
app/api/user/password/route.ts
CHANGED
|
@@ -14,12 +14,12 @@ import {
|
|
| 14 |
} from "@/lib/api/password-reset";
|
| 15 |
|
| 16 |
const requestResetSchema = z.object({
|
| 17 |
-
email: z.
|
| 18 |
});
|
| 19 |
|
| 20 |
const resetPasswordSchema = z
|
| 21 |
.object({
|
| 22 |
-
email: z.
|
| 23 |
token: z.string().min(1),
|
| 24 |
newPassword: z
|
| 25 |
.string()
|
|
|
|
| 14 |
} from "@/lib/api/password-reset";
|
| 15 |
|
| 16 |
const requestResetSchema = z.object({
|
| 17 |
+
email: z.email("Email không hợp lệ"),
|
| 18 |
});
|
| 19 |
|
| 20 |
const resetPasswordSchema = z
|
| 21 |
.object({
|
| 22 |
+
email: z.email(),
|
| 23 |
token: z.string().min(1),
|
| 24 |
newPassword: z
|
| 25 |
.string()
|
lib/api/audit.ts
CHANGED
|
@@ -28,7 +28,9 @@ export function logAudit(entry: Omit<AuditLogEntry, "timestamp">): void {
|
|
| 28 |
|
| 29 |
// Log to console in development
|
| 30 |
if (process.env.NODE_ENV === "development") {
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
// Add to in-memory store (for development only)
|
|
|
|
| 28 |
|
| 29 |
// Log to console in development
|
| 30 |
if (process.env.NODE_ENV === "development") {
|
| 31 |
+
process.stdout.write(
|
| 32 |
+
`[AUDIT] ${entry.action} on ${entry.entityType} (${entry.entityId}) by user ${entry.userId}\n`,
|
| 33 |
+
);
|
| 34 |
}
|
| 35 |
|
| 36 |
// Add to in-memory store (for development only)
|
lib/validations.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const phoneSchema = z
|
|
| 7 |
.string()
|
| 8 |
.regex(/^0\d{9}$/, "Invalid Vietnamese phone number");
|
| 9 |
|
| 10 |
-
export const emailSchema = z.
|
| 11 |
|
| 12 |
export const addressSchema = z.object({
|
| 13 |
street: z.string().min(1, "Address is required"),
|
|
|
|
| 7 |
.string()
|
| 8 |
.regex(/^0\d{9}$/, "Invalid Vietnamese phone number");
|
| 9 |
|
| 10 |
+
export const emailSchema = z.email("Invalid email address");
|
| 11 |
|
| 12 |
export const addressSchema = z.object({
|
| 13 |
street: z.string().min(1, "Address is required"),
|