fix(rbac): guard noUncheckedIndexedAccess in name derivation and newStaff insert
CI / Test (push) Successful in 10s
CI / Lint & Typecheck (push) Successful in 10s
CI / Build & Push Docker Images (push) Successful in 43s
CI / Test (pull_request) Successful in 9s
CI / Lint & Typecheck (pull_request) Successful in 10s
CI / Build & Push Docker Images (pull_request) Failing after 10s
CI / Test (push) Successful in 10s
CI / Lint & Typecheck (push) Successful in 10s
CI / Build & Push Docker Images (push) Successful in 43s
CI / Test (pull_request) Successful in 9s
CI / Lint & Typecheck (pull_request) Successful in 10s
CI / Build & Push Docker Images (pull_request) Failing after 10s
With noUncheckedIndexedAccess:true, split("@")[0] returns string|undefined,
making `name` typed as string|undefined and failing the notNull staff.name
insert constraint. Fix by using ?? fallback on the array access.
Also add newStaff null guard after .returning() destructure — array
destructuring yields T|undefined with noUncheckedIndexedAccess enabled.
This commit is contained in:
@@ -127,15 +127,14 @@ export const resolveStaffMiddleware: MiddlewareHandler<AppEnv> = async (
|
|||||||
|
|
||||||
if (oidcAccount) {
|
if (oidcAccount) {
|
||||||
// Derive name: prefer jwt.name, fall back to email prefix, then "Unknown"
|
// Derive name: prefer jwt.name, fall back to email prefix, then "Unknown"
|
||||||
const name =
|
const emailPrefix = jwt.email.split("@")[0] ?? "Unknown";
|
||||||
jwt.name?.trim() ||
|
const name = jwt.name?.trim() || emailPrefix;
|
||||||
(jwt.email ? jwt.email.split("@")[0] : "Unknown");
|
|
||||||
|
|
||||||
const [newStaff] = await db
|
const [newStaff] = await db
|
||||||
.insert(staff)
|
.insert(staff)
|
||||||
.values({
|
.values({
|
||||||
userId: jwt.sub,
|
userId: jwt.sub,
|
||||||
email: jwt.email ?? "",
|
email: jwt.email,
|
||||||
name,
|
name,
|
||||||
role: "groomer",
|
role: "groomer",
|
||||||
isSuperUser: false,
|
isSuperUser: false,
|
||||||
@@ -143,6 +142,10 @@ export const resolveStaffMiddleware: MiddlewareHandler<AppEnv> = async (
|
|||||||
})
|
})
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
|
if (!newStaff) {
|
||||||
|
return c.json({ error: "Forbidden: auto-provision failed" }, 500);
|
||||||
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`[rbac] auto-provisioned staff record for OIDC user: ${jwt.sub} -> staff:${newStaff.id} (${name})`
|
`[rbac] auto-provisioned staff record for OIDC user: ${jwt.sub} -> staff:${newStaff.id} (${name})`
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user