Skip to main content

Authentication

Prime ships a complete authentication system out of the box. Users can sign in with a password, a magic link, or their Google account. Two-factor authentication and suspicious login detection are included.

Sign in / Sign up​

Email and password are the default. Passwords are hashed with Argon2. On signup, users receive a verification email before they can access the app.

MethodEndpointDescription
POST/authSign in with email + password
POST/auth/refreshExchange refresh token for a new access token
GET/authGet current authenticated user
DELETE/authSign out (invalidates the session)

All sign-in endpoints are rate-limited to prevent brute force attacks.

JWT tokens​

Authentication uses short-lived access tokens and longer-lived refresh tokens:

TOKEN_SECRET=your_jwt_secret       # Signs access tokens
REFRESH_SECRET=your_refresh_secret # Signs refresh tokens

Generate strong secrets with:

openssl rand -hex 32

Google OAuth​

Users can sign in with their Google account. See Google Auth Setup for credentials.

MethodEndpointDescription
POST/auth/googleSign in with a Google ID token
POST/auth/oauthSign in with a generic OAuth provider token ({ token, provider })

Passwordless sign-in via a one-time link emailed to the user. The link expires after MAGIC_LINK_EXPIRY_MINUTES (default: 5 minutes).

MethodEndpointDescription
POST/auth/magicRequest a magic link
POST/auth/magic/verifyVerify the token from the link

Two-Factor Authentication (2FA)​

Users can enable TOTP-based 2FA (Google Authenticator, Authy, etc.). Backup codes are generated at setup time.

Sign-in flow with 2FA enabled:

  1. User submits email + password → server responds 200 with { "2fa_required": true, "token": "<short-lived jwt>" }
  2. User submits their 6-digit OTP together with that token ({ code, jwt }) → server returns tokens
MethodEndpointDescription
POST/auth/otpSubmit OTP code during sign-in (body: { code, jwt })

2FA setup, enable/disable, and backup code management are handled through the Users endpoints.

Email Verification​

New accounts must verify their email before accessing the app. See Email Verification for TTL and retry configuration.

MethodEndpointDescription
POST/auth/verify-emailVerify token from the email link
POST/auth/resend-verificationResend the verification email

Password Reset​

MethodEndpointDescription
POST/auth/password/reset/requestRequest a reset email
POST/auth/password/resetSubmit new password with reset token (body: { email, jwt, password })

The reset token is single-use and expires after a short window.

Suspicious Login Detection​

When a user signs in from an unfamiliar device or location, an alert email is sent notifying them of the new sign-in.

Multi-account support​

A single user can belong to multiple accounts. After sign-in, the user selects the active account context. The access token encodes the active account and the user can switch without re-authenticating.