Skip to main content

useInviteLinks

Location: src/hooks/useInviteLinks.js

Overview

This file exports four items for the invite-only signup system:

  • useInviteLinks -- manage the current user's invite links (create, revoke, list)
  • useInviteLookup -- look up an invite code to validate it (for the signup flow)
  • useInviteOnSignup -- consume an invite code during the registration process
  • getInviteUrl -- utility function to build a shareable invite URL

Each user can have up to 10 active invite links at a time.


Signature

function useInviteLinks(): {
invites: InviteRow[],
activeInvites: InviteRow[],
usedInvites: InviteRow[],
loading: boolean,
error: string | null,
createInvite: (note?: string | null, intendedFor?: string | null) => Promise<{ success: boolean, data?: InviteRow, error?: string }>,
revokeInvite: (inviteId: string) => Promise<{ success: boolean, error?: string }>,
refetch: () => Promise<void>,
canCreateMore: boolean,
activeCount: number,
maxInvites: number
}

Parameters

None. Automatically resolves the current authenticated user via the get_my_invite_links RPC function.

Return Value

PropertyTypeDescription
invitesInviteRow[]All invite links for the current user (active, used, revoked, expired).
activeInvitesInviteRow[]Only active, non-expired invites.
usedInvitesInviteRow[]Invites that have been used by someone signing up.
loadingbooleantrue while the fetch is in progress.
errorstring | nullError message if the fetch failed.
createInvite(note?, intendedFor?) => PromiseCreate a new invite link. note is an optional personal note (e.g. "For my friend Sarah"). intendedFor is an optional name of the intended recipient. Calls the create_invite_link RPC.
revokeInvite(inviteId) => PromiseRevoke an active invite link. Calls the revoke_invite_link RPC.
refetch() => Promise<void>Re-fetch all invites.
canCreateMorebooleantrue if the user has fewer than 10 active invites.
activeCountnumberNumber of currently active invites.
maxInvitesnumberMaximum allowed active invites (currently 10).

Usage

function InviteManager() {
const { activeInvites, loading, createInvite, revokeInvite, canCreateMore } = useInviteLinks();

const handleCreate = async () => {
const { success, error } = await createInvite('For my friend');
if (!success) console.error(error);
};

if (loading) return <Skeleton />;

return (
<div>
<button onClick={handleCreate} disabled={!canCreateMore}>
Create Invite Link
</button>
{activeInvites.map(invite => (
<div key={invite.id}>
<code>{getInviteUrl(invite.code)}</code>
<button onClick={() => revokeInvite(invite.id)}>Revoke</button>
</div>
))}
</div>
);
}

useInviteLookup

Signature

function useInviteLookup(
code?: string | null
): {
invite: InviteLookupResult | null,
loading: boolean,
error: string | null,
isValid: boolean,
lookupInvite: (inviteCode: string) => Promise<void>
}

Parameters

ParameterTypeRequiredDescription
codestring | nullNoAn invite code to automatically look up when the value changes.

Return Value

PropertyTypeDescription
inviteInviteLookupResult | nullThe lookup result if the code is valid, or null if invalid/not found.
loadingbooleantrue while the lookup is in progress.
errorstring | nullError message if the code is invalid, expired, or not found.
isValidbooleantrue if the invite code is valid and can be used.
lookupInvite(inviteCode: string) => Promise<void>Manually trigger a lookup for a specific code.

Usage

function JoinPage({ inviteCode }) {
const { invite, isValid, loading, error } = useInviteLookup(inviteCode);

if (loading) return <Skeleton />;
if (!isValid) return <p>Invalid invite: {error}</p>;

return <p>You were invited by {invite.inviter_name}!</p>;
}

useInviteOnSignup

Signature

function useInviteOnSignup(): {
useInvite: (code: string, newUserId: string) => Promise<{ success: boolean, error?: string }>,
processing: boolean,
error: string | null
}

Parameters

None.

Return Value

PropertyTypeDescription
useInvite(code, newUserId) => PromiseConsume an invite code during signup. Links the new user to the inviter. Calls the use_invite RPC.
processingbooleantrue while the invite is being consumed.
errorstring | nullError message if the operation failed.

getInviteUrl

Signature

function getInviteUrl(code: string): string

A pure utility function (not a hook) that builds a full invite URL from a code.

ParameterTypeRequiredDescription
codestringYesThe invite code.

Returns a URL in the format {origin}/join/{code}. Falls back to https://commonplace.app if window.location.origin is unavailable.


Last updated: 2026-02-07