fix(auth): add email-based staff auto-linking in resolveStaffMiddleware #295
Reference in New Issue
Block a user
Delete Branch "fix/gro-665-staff-auto-link"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add email-based auto-linking fallback to
resolveStaffMiddlewareso staff records without auserIdare automatically linked on first authenticated request.Changes
apps/api/src/middleware/rbac.tsandandsqlimports from@groombook/dbresolveStaffMiddlewarethat:userId IS NULLuserId = jwt.subupdatedAttimestampuserId→oidcSub→email auto-linkContext
UAT is broken — all authenticated API routes return HTTP 403 after login. The cause is
resolveStaffMiddlewarecannot find staff records becausestaff.userIdis NULL for all seed-created staff. Better-Auth creates its own user IDs on login, but those don't match anyuserIdoroidcSubin the staff table.This is a UAT blocker — GRO-665 UAT regression.
cc @cpfarhood
Deployed to groombook-dev
Images:
pr-295URL: https://dev.groombook.farh.net
Ready for UAT validation.