Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(users): clear revokedAt when re-inviting a user (#1609)

Brad Barbin2953fe7f109d
diff --git a/apps/erp/app/modules/users/users.server.ts b/apps/erp/app/modules/users/users.server.ts
index 3387dbc1f0..013431aac5 100644
--- a/apps/erp/app/modules/users/users.server.ts
+++ b/apps/erp/app/modules/users/users.server.ts
@@ -888,14 +888,20 @@ export async function insertInvite(
client: SupabaseClient<Database>,
invite: InviteInsert
) {
- return client
- .from("invite")
- .upsert([{ ...invite, acceptedAt: null }], {
- onConflict: "email, companyId",
- ignoreDuplicates: false
- })
- .select("*")
- .single();
+ return (
+ client
+ .from("invite")
+ // Re-inviting an email that already has an invite row reuses it via the
+ // onConflict upsert. Clear both terminal states so a previously revoked or
+ // accepted invite becomes redeemable again — otherwise the acceptance
+ // loader (invite.$code.tsx) rejects the row and it can never be accepted.
+ .upsert([{ ...invite, acceptedAt: null, revokedAt: null }], {
+ onConflict: "email, companyId",
+ ignoreDuplicates: false
+ })
+ .select("*")
+ .single()
+ );
}
async function insertSupplierAccount(