Repository navigation
fix(team): return the direct invite link so shared invites don't 404 - #340
Merged
Merged
Conversation
inviteMember returned the dashboard "share this link directly" URL as
`/auth/confirm?next=/invite/{token}`. That base only works once the
Supabase invite EMAIL template appends token_hash + type; opened directly
(exactly what the copy/share affordance does) it has neither, so
/auth/confirm bounced to /sign-in?error=auth_confirm_missing_params.
- Return the direct, self-contained `/invite/{token}` accept link for the
admin to share (matches what resendInvitation already returned). That
page looks the invitation up by token and routes to sign-up/accept on
its own — no Supabase OTP params needed — so it works for new users,
signed-out users, and existing users being re-invited alike.
- Keep `/auth/confirm?next=...` as the EMAIL `redirectTo` only (renamed to
`emailRedirectTo` for clarity), where the template decorates it.
- Replace the silent `catch {}` around inviteUserByEmail with a warn log:
it only emails brand-new addresses and errors for already-registered
users (Supabase limitation) — that's expected, the share link is the
path, but genuine SMTP failures for new users are now diagnosable.
Re-inviting a removed member (profile detached via organization_id=null)
now works end to end: the partial unique index only blocks *pending*
dupes, and acceptInvitation re-attaches the existing profile to the org.
There was a problem hiding this comment.
Pull request overview
This PR fixes the team invite “share this link directly” URL by returning a direct /invite/{token} link from inviteMember, avoiding reliance on Supabase email-only OTP parameters that caused /auth/confirm links to 404 when opened directly.
Changes:
- Return a direct, self-contained
/invite/{token}link for admins to copy/share from the dashboard. - Keep
/auth/confirm?next=...as the SupabaseredirectTovalue intended for email-template augmentation (token_hash/type). - Replace the silent
inviteUserByEmailerror swallow with a warning log for diagnosability.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+256
to
+260
| console.warn( | ||
| `[invite] Supabase invite email not sent for ${normalizedEmail} (existing user or SMTP): ${ | ||
| err instanceof Error ? err.message : String(err) | ||
| }`, | ||
| ); |
Comment on lines
244
to
265
| try { | ||
| await supabaseAdmin.auth.admin.inviteUserByEmail(normalizedEmail, { | ||
| redirectTo: inviteLink, | ||
| redirectTo: emailRedirectTo, | ||
| data: { invitation_token: token }, | ||
| }); | ||
| } catch { | ||
| // Supabase may fail if user already has an account; we still keep the | ||
| // invitation row so that the direct link works. | ||
| } catch (err) { | ||
| // inviteUserByEmail only emails BRAND-NEW addresses — it errors for an | ||
| // email that's already registered (Supabase can't "create" that user), so | ||
| // existing users never get the Supabase invite mail. That's acceptable: | ||
| // the invitation row is saved and the admin shares `shareLink` directly. | ||
| // Log the reason so genuine SMTP failures for new users stay diagnosable | ||
| // instead of vanishing into a silent catch. | ||
| console.warn( | ||
| `[invite] Supabase invite email not sent for ${normalizedEmail} (existing user or SMTP): ${ | ||
| err instanceof Error ? err.message : String(err) | ||
| }`, | ||
| ); | ||
| } | ||
|
|
||
| revalidatePath('/dashboard/settings'); | ||
| return { invitation, inviteLink }; | ||
| return { invitation, inviteLink: shareLink }; | ||
| } |
- inviteMember now returns `emailSent` (true only when inviteUserByEmail didn't throw). The invite dialog uses it: shows "Invitation sent … share this link" when an email went out, and "No email was sent — this address may already have an account. Share this link with them directly" when it didn't, instead of always claiming an email was sent. - The swallowed-error log no longer includes the invitee's email address (PII in persistent logs) — it logs invitation id + org id and passes the error object for stack/diagnostics. Addresses the Copilot review on #340.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a broken team-invite link. When an admin invited a member and used the dashboard's "share this link directly" affordance (copy button), the copied URL was
…/auth/confirm?next=/invite/{token}— which redirected the invitee to…/sign-in?error=auth_confirm_missing_params.Root cause:
/auth/confirmonly works when Supabase's invite email template appendstoken_hash+type.inviteMemberwas handing that same/auth/confirmbase back to the dashboard as the shareable link, so opening it directly (notoken_hash/type) hit the "missing params" guard.resendInvitationalready returned the correct direct form;inviteMembernow matches.Changes (
web/src/lib/actions/team.ts)/invite/{token}accept link for the admin to share. That page looks the invitation up by token and routes to sign-up/accept on its own — no Supabase OTP params — so it works for new users, signed-out users, and existing users being re-invited alike./auth/confirm?next=…as the emailredirectToonly (renamedemailRedirectTofor clarity), where the invite email template decorates it withtoken_hash+type.catch {}aroundinviteUserByEmailwith aconsole.warn.inviteUserByEmailonly emails brand-new addresses and errors for already-registered emails (a Supabase limitation) — expected, since the share link is the delivery path, but genuine SMTP failures for new users are now diagnosable instead of vanishing.Re-inviting a removed member
This also unblocks the "removed then re-invited" case raised in review:
removeMemberdetaches the profile (organization_id = null) but keeps the auth user + profile row.invitations_org_email_pending_idxonly blocks duplicate pending invites, so a fresh invite for a previously-accepted/removed user inserts fine.acceptInvitationre-attaches the existing profile to the org, so opening the direct link and signing in re-joins them.Note: auto-emailing existing users (vs. sharing the link) is intentionally out of scope — the app has no transactional email provider beyond Supabase Auth, and Supabase can't send an invite email to an already-registered address. Tracked as a possible follow-up (magic-link or Resend).
Type of change
fix— Bug fixHow to test
…/invite/{token}(not/auth/confirm?…).auth_confirm_missing_params.yarn typecheck,yarn lint,yarn format:checkpass fromweb/.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (fromweb/)yarn typecheckpasses (fromweb/)yarn format:checkpasses (fromweb/)