invitation flow finished
This commit is contained in:
1 parent
0817e8e72b
commit
d4fae890bb
5 files changed
+26
-9
No files matched your search
@@ -54,13 +54,13 @@ export async function GET(request: NextRequest) {
|
||||
// Gym filter: SuperAdmin can see all, others only their gym
|
||||
if (role === "superAdmin") {
|
||||
// If gymId param provided, filter by it
|
||||
if (targetGymId && metadata?.gymId !== targetGymId) {
|
||||
if (targetGymId && (metadata?.gymId ?? null) !== targetGymId) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// Non-superAdmins: must match their gym
|
||||
return metadata?.gymId === userGymId;
|
||||
// Non-superAdmins: must match their gym (normalize null/undefined)
|
||||
return (metadata?.gymId ?? null) === (userGymId ?? null);
|
||||
}
|
||||
})
|
||||
.map((inv) => ({
|
||||
@@ -214,9 +214,9 @@ export async function POST(req: Request) {
|
||||
const invitation = await client.invitations.createInvitation({
|
||||
emailAddress: inviteeEmail,
|
||||
publicMetadata: {
|
||||
roleAssigned,
|
||||
role: roleAssigned,
|
||||
gymId: gymIdForInvite,
|
||||
inviterUserId: inviter.id,
|
||||
createdBy: inviter.id,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -85,14 +85,12 @@ export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const client = await clerkClient();
|
||||
|
||||
// Build publicMetadata - only include gymId if it exists
|
||||
// Build publicMetadata with consistent field names
|
||||
const publicMetadata: Record<string, any> = {
|
||||
role: data.role,
|
||||
createdBy: userId,
|
||||
gymId: assignedGymId ?? null,
|
||||
};
|
||||
if (assignedGymId) {
|
||||
publicMetadata.gymId = assignedGymId;
|
||||
}
|
||||
|
||||
// Determine redirect URL based on role
|
||||
// Staff (admin, trainer, superAdmin) → Admin web app
|
||||
|
||||
Reference in new issue
Block a user