* Check if a user belongs to an organization. * In dev mode, checks local DB. In production, calls WorkOS API.
(userId: string, orgId: string)
| 23 | * In dev mode, checks local DB. In production, calls WorkOS API. |
| 24 | */ |
| 25 | async function isOrgMember(userId: string, orgId: string): Promise<boolean> { |
| 26 | if (isDevModeEnabled()) { |
| 27 | const result = await query<{ count: string }>( |
| 28 | `SELECT COUNT(*)::text AS count FROM organization_memberships |
| 29 | WHERE workos_user_id = $1 AND workos_organization_id = $2`, |
| 30 | [userId, orgId] |
| 31 | ); |
| 32 | return parseInt(result.rows[0]?.count || '0') > 0; |
| 33 | } |
| 34 | if (!workos) return false; |
| 35 | const memberships = await workos.userManagement.listOrganizationMemberships({ userId, organizationId: orgId }); |
| 36 | return memberships.data.length > 0; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Create certification routes. |
no test coverage detected