Skip to content

Commit 4126123

Browse files
fix(auth): set app_metadata.tenant_id in joinCurrentSchool action
New users joining a school via /join-school had null tenant_id in app_metadata, so the JWT hook couldn't inject tenant claims. Client-side exam submissions then failed RLS (get_tenant_id() returned wrong tenant). Fix: set app_metadata.tenant_id via admin client before refreshing the session, same pattern as create_school RPC. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 957698f commit 4126123

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

app/actions/join-school.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export async function joinCurrentSchool() {
113113
{ onConflict: 'user_id,tenant_id', ignoreDuplicates: true }
114114
)
115115

116+
// Set app_metadata.tenant_id so the JWT hook includes it in claims
117+
await adminClient.auth.admin.updateUserById(user.id, {
118+
app_metadata: { tenant_id: tenantId },
119+
})
120+
116121
// Update user's preferred tenant
117122
await supabase.auth.updateUser({
118123
data: { preferred_tenant_id: tenantId }

0 commit comments

Comments
 (0)