Spaces:
Running
Running
Reject client supplied account roles
Browse files- src/server.ts +2 -2
- src/supabase.ts +1 -0
src/server.ts
CHANGED
|
@@ -51,7 +51,7 @@ const passwordResetRequestLimiter = rateLimit({ windowMs: 60 * 60 * 1000, limit:
|
|
| 51 |
const passwordRecoveryLimiter = rateLimit({ windowMs: 15 * 60 * 1000, limit: 15, standardHeaders: "draft-8", legacyHeaders: false });
|
| 52 |
const apiLimiter = rateLimit({ windowMs: 15 * 60 * 1000, limit: 3000, standardHeaders: "draft-8", legacyHeaders: false });
|
| 53 |
const analysisUploadLimiter = rateLimit({ windowMs: 15 * 60 * 1000, limit: 4, standardHeaders: "draft-8", legacyHeaders: false });
|
| 54 |
-
const signupSchema = z.object({ fname: z.string().trim().min(1).max(100), lname: z.string().trim().min(1).max(100), email: z.string().trim().toLowerCase().email().max(255), password: z.string().min(8).max(128), academy: z.string().trim().max(150).optional() });
|
| 55 |
const loginSchema = z.object({ email: z.string().trim().toLowerCase().email(), password: z.string().min(1).max(128) });
|
| 56 |
const passwordResetRequestSchema = z.object({ email: z.string().trim().toLowerCase().email().max(255) });
|
| 57 |
const passwordRecoveryVerifySchema = z.object({ tokenHash: z.string().trim().min(1).max(512) });
|
|
@@ -62,7 +62,7 @@ const profileSchema = z.object({
|
|
| 62 |
lname: z.string().trim().min(1).max(100),
|
| 63 |
academy: z.string().trim().max(150).transform((value) => value || null).nullable(),
|
| 64 |
role: z.enum(profileRoles).nullable(),
|
| 65 |
-
});
|
| 66 |
const passwordSchema = z.object({ currentPassword: z.string().max(128).optional(), newPassword: z.string().min(8).max(128) });
|
| 67 |
const actionReviewSchema = z.object({
|
| 68 |
coachScore: z.number().int().min(0).max(10).nullable(),
|
|
|
|
| 51 |
const passwordRecoveryLimiter = rateLimit({ windowMs: 15 * 60 * 1000, limit: 15, standardHeaders: "draft-8", legacyHeaders: false });
|
| 52 |
const apiLimiter = rateLimit({ windowMs: 15 * 60 * 1000, limit: 3000, standardHeaders: "draft-8", legacyHeaders: false });
|
| 53 |
const analysisUploadLimiter = rateLimit({ windowMs: 15 * 60 * 1000, limit: 4, standardHeaders: "draft-8", legacyHeaders: false });
|
| 54 |
+
const signupSchema = z.object({ fname: z.string().trim().min(1).max(100), lname: z.string().trim().min(1).max(100), email: z.string().trim().toLowerCase().email().max(255), password: z.string().min(8).max(128), academy: z.string().trim().max(150).optional() }).strict();
|
| 55 |
const loginSchema = z.object({ email: z.string().trim().toLowerCase().email(), password: z.string().min(1).max(128) });
|
| 56 |
const passwordResetRequestSchema = z.object({ email: z.string().trim().toLowerCase().email().max(255) });
|
| 57 |
const passwordRecoveryVerifySchema = z.object({ tokenHash: z.string().trim().min(1).max(512) });
|
|
|
|
| 62 |
lname: z.string().trim().min(1).max(100),
|
| 63 |
academy: z.string().trim().max(150).transform((value) => value || null).nullable(),
|
| 64 |
role: z.enum(profileRoles).nullable(),
|
| 65 |
+
}).strict();
|
| 66 |
const passwordSchema = z.object({ currentPassword: z.string().max(128).optional(), newPassword: z.string().min(8).max(128) });
|
| 67 |
const actionReviewSchema = z.object({
|
| 68 |
coachScore: z.number().int().min(0).max(10).nullable(),
|
src/supabase.ts
CHANGED
|
@@ -65,6 +65,7 @@ export async function syncProfile(user: User, profile?: { fname?: string; lname?
|
|
| 65 |
email: user.email,
|
| 66 |
academy: profile?.academy ?? metadata.academy ?? null,
|
| 67 |
role: profile?.role ?? metadata.role ?? null,
|
|
|
|
| 68 |
};
|
| 69 |
const { error } = await supabaseAdmin.from("users").insert({ ...fields, password_hash: profile?.passwordHash ?? await randomPasswordHash() });
|
| 70 |
if (error) throw new Error(`Unable to create user profile: ${error.message}`);
|
|
|
|
| 65 |
email: user.email,
|
| 66 |
academy: profile?.academy ?? metadata.academy ?? null,
|
| 67 |
role: profile?.role ?? metadata.role ?? null,
|
| 68 |
+
account_role: "user",
|
| 69 |
};
|
| 70 |
const { error } = await supabaseAdmin.from("users").insert({ ...fields, password_hash: profile?.passwordHash ?? await randomPasswordHash() });
|
| 71 |
if (error) throw new Error(`Unable to create user profile: ${error.message}`);
|