Authentication¶
TL;DR
Canviq uses magic link login with custom HMAC-signed session cookies. No passwords, no OAuth. Sessions are AES-256-GCM encrypted and stored in httpOnly cookies with 8-hour expiry.
Authentication Flow¶
Canviq uses a single authentication method: magic link login via email.
User enters email → Magic link sent via Resend → User clicks link →
Session cookie created → Redirected to dashboard
There are no passwords and no Supabase Auth. The system uses a custom public.users table with HMAC-signed session cookies.
Magic link is not the only way in. Members can also sign in with GitHub (/api/auth/github, via Arctic), and guests can continue with Google (/api/auth/guest/google). Both land in the same session, so everything below about cookies and revocation applies to them too.
Step 1: Request Magic Link¶
Navigate to /auth/login and enter your email address:
A magic link is sent to the email address via Resend. The link contains a one-time token stored in the auth_magic_links table.
Step 2: Confirm Login¶
Click the magic link in your email, which redirects to /auth/confirm?token=.... The page says which account the link signs you in as ("This link signs you in as ..."). If a different account is already signed in on that browser, it names both, so you can stop if you did not request the link. The invite page does the same. Click Sign in to continue: the server verifies the token, creates a session, and redirects to the dashboard.
If you belong to more than one organization, signing in on an organization's own address (for example acme.canviq.app) takes you into that organization when you are a member of it. Signing in elsewhere, with a magic link or with GitHub, shows the organization picker when there is no clear choice.
Addresses that cannot receive email¶
If an address has hard-bounced or marked a Canviq email as spam, the email provider stops delivering to it. Canviq remembers this and does not send a magic link to that address. The login page says it can't deliver email to that address and suggests signing in with GitHub or contacting support, instead of telling you to check your inbox.
Step 3: Session Created¶
On successful verification, the server:
- Finds or creates the user in the
userstable - Looks up the user's organization membership in
organization_members - Creates an encrypted + signed session cookie
Session Management¶
Session Cookie¶
Canviq uses a single cookie named feedback_session:
| Property | Value |
|---|---|
| Name | feedback_session |
| Encryption | AES-256-GCM (IV + authTag + ciphertext) |
| Signing | HMAC-SHA256 (constant-time comparison) |
| httpOnly | Yes (prevents JavaScript access) |
| secure | Yes in production (HTTPS only) |
| sameSite | lax (CSRF protection) |
| maxAge | 8 hours |
| Rotation | Auto-rotates at 4 hours (50% threshold) |
Session Data¶
The encrypted cookie payload contains:
interface SessionData {
userId: string // UUID from public.users
email: string
organizationId: string // UUID from organizations
organizationRole: 'owner' | 'admin' | 'member'
expiresAt: number // Unix timestamp
}
Session Revocation¶
Sessions can be revoked via a Redis deny-list:
- Revocation stores the time of the revocation for that user in one organization, in an Upstash Redis key with an 8-hour TTL
- The
auth()function checks the deny-list on every request. It rejects only sessions issued at or before the revocation time, so signing in again works straight away - An admin revocation applies to one organization, not to the user's other organizations
- If Redis is unavailable, Canviq keeps recent confirmed revocations for a short time and rejects sessions it cannot check, rather than allowing them (fail-closed)
- Admin can revoke sessions via
POST /api/admin/sessions/revoke. Only an owner can revoke an owner's sessions
Signing Out¶
Deletes the feedback_session cookie and revokes your sessions in that organization on the server, on every device, so a copy of the cookie stops working too.
Multi-Tenancy¶
Authentication is tightly coupled with organization membership:
- Middleware extracts the organization from the subdomain (e.g.,
acme.canviq.app→ org slugacme) - Session includes
organizationIdandorganizationRole - RLS policies use
current_user_id()andcurrent_organization_id()(set via request headers from the server client)
Users without an organization membership cannot create a session.
Authorization Model¶
Roles¶
| Role | Description |
|---|---|
owner | Full control including billing |
admin | Manage submissions, surveys, team |
member | Submit, vote, comment |
RLS Functions¶
All row-level security policies use these PostgreSQL functions:
| Function | Returns | Purpose |
|---|---|---|
current_user_id() | UUID | Current user from request headers |
current_organization_id() | UUID | Current org from request headers |
is_org_member() | boolean | Is the user a member of the current org |
is_org_admin() | boolean | Is the user an admin or owner |
is_team_member(user_id) | boolean | Legacy: checks team_members table |
Security Notes¶
- No passwords stored: Magic link and OAuth only, no password hashing
- OAuth: GitHub for members and Google for guests, both handled in application code via Arctic rather than through Supabase Auth
- Session secret:
SESSION_SECRETenv var required (min 32 chars) - Encryption: AES-256-GCM with random IV per encryption
- Signing: HMAC-SHA256 with constant-time comparison to prevent timing attacks
- Revocation: Redis-backed deny-list with automatic TTL expiry, failing closed when Redis cannot be reached
Next Steps¶
- Quickstart: Get started with the platform
- API Reference: REST API endpoints