Authentication
Sign-in methods in TimeWren: email and password, magic link, passkeys, 2FA, SMS, OAuth providers, the first admin account and secret rotation.
TimeWren uses Better Auth. Email and password sign-in always works. Everything else is optional and switches on when you set the matching variables. All variables are listed in .env.example; see also Environment variables.
Email and password
Users sign up with email and password. Passwords are reset by mail (the link is valid for 1 hour).
Email verification is required by default: a new user must click the link in the verification mail (valid for 24 hours) before signing in. Verification mails need a configured mail transport, see Email.
You can switch verification off only when no mail transport is configured:
REQUIRE_EMAIL_VERIFICATION=falseThe flag is ignored as soon as SMTP or Resend is set. The app logs a warning in that case.
Warning: With verification off, anyone who can reach the instance can create an account with any address, including the address in
ADMIN_EMAIL. Use it to get started, then configure mail and remove the line before exposing the instance.
Sign-in attempts are rate limited: 5 password sign-ins per 15 minutes, 10 sign-ups per 15 minutes.
The first admin
The instance admin role is assigned automatically:
- If
ADMIN_EMAILis set (comma separated list), the account with that address becomes instance admin. - If it is empty, the first account created becomes admin, but only while the instance has no admin yet.
Promotion happens at sign-up and at sign-in. When verification is required, only a verified address is promoted. Every new user also gets a personal workspace (an organization of which they are the owner).
ADMIN_EMAIL=you@example.comMagic link
Passwordless sign-in by mail. The link is valid for 15 minutes. It needs a working mail transport and has no setting of its own.
Passkeys
Users can register passkeys (WebAuthn) under their security settings and sign in with them. Passkeys are bound to a domain, called the relying-party ID. By default it is the hostname of NEXT_PUBLIC_APP_URL, so the app must be served over HTTPS on its final domain before people register passkeys. If you change the domain, existing passkeys stop working.
Set AUTH_RP_ID only if you split the app and marketing site across hosts and want passkeys bound to the parent domain:
AUTH_RP_ID=example.comTwo-factor authentication
Users can turn on two-factor authentication in their security settings. It supports:
- TOTP authenticator apps (6 digits, 30 second period)
- 10 backup codes
- A one-time code by mail as a fallback (needs a mail transport)
Two-factor verification attempts are rate limited to 10 per 15 minutes.
SMS login
Sign-in with a phone number and a 6-digit code (valid for 5 minutes). Sending uses MessageBird:
MESSAGEBIRD_API_KEY=your-messagebird-key
MESSAGEBIRD_ORIGINATOR=TimeWrenWithout MESSAGEBIRD_API_KEY, requesting a code fails with a "not configured" error. A user who signs up by phone only gets a placeholder email address on your mail domain (EMAIL_DOMAIN, defaulting to the marketing or app host). The text message itself is currently written in Danish.
OAuth providers
Each provider needs an OAuth app that you register yourself. A provider is offered only when both its variables are set. The callback URL is always {NEXT_PUBLIC_APP_URL}/api/auth/callback/<id>.
| Provider | Id | Variables | Callback URL |
|---|---|---|---|
google | GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET | https://timewren.example.com/api/auth/callback/google | |
| GitHub | github | GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET | https://timewren.example.com/api/auth/callback/github |
| Discord | discord | DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET | https://timewren.example.com/api/auth/callback/discord |
| Apple | apple | APPLE_CLIENT_ID, APPLE_TEAM_ID, APPLE_KEY_ID, APPLE_PRIVATE_KEY | https://timewren.example.com/api/auth/callback/apple |
| Microsoft Entra ID | microsoft-entra-id | MICROSOFT_CLIENT_ID, MICROSOFT_CLIENT_SECRET, MICROSOFT_TENANT_ID | https://timewren.example.com/api/auth/callback/microsoft-entra-id |
Notes:
- The Google client is shared with the Google Calendar integration, which has its own callback URL.
- Sign in with Apple:
APPLE_CLIENT_IDis the Services ID. The client secret is generated from your.p8key (APPLE_PRIVATE_KEY, PEM text with\nline breaks or the whole file base64 encoded) when the app starts.APPLE_APP_BUNDLE_IDENTIFIER(defaultdk.timetrack.app) is the iOS bundle id used for native sign-in. - Microsoft:
MICROSOFT_TENANT_IDdefaults tocommon(any Microsoft account). Set a tenant GUID to restrict sign-in to one organization. Seedocs/MICROSOFT-LOGIN-SETUP.mdin the repository for the Azure steps. - Accounts from Google and GitHub are linked automatically when the email address matches an existing account. Discord accounts are only linked when Discord reports the email address as verified.
Trusted origins
Browsers send requests from the origin of NEXT_PUBLIC_APP_URL, which is always trusted. If the app is also reached from another web origin (for example a second domain), add it:
TRUSTED_ORIGINS=https://timewren.example.org,https://time.example.comThe value is a comma separated list of https://host origins. Invalid entries are skipped.
Sessions
Sessions last 7 days. An active session is extended at most once every 24 hours. The session cookie is host-only by default. AUTH_COOKIE_DOMAIN shares it across subdomains and AUTH_COOKIE_PREFIX changes its name (default better-auth); both are only needed with a split app and marketing host.
Rotating BETTER_AUTH_SECRET
BETTER_AUTH_SECRET is the Better Auth secret. Among other things it encrypts the OAuth login tokens stored in the database, and changing it directly makes those tokens unreadable until users sign in again. To rotate it safely, use versioned secrets:
BETTER_AUTH_SECRETS=2:the-new-long-random-secret,1:the-old-long-random-secretThe format is <version>:<secret> separated by commas. The first entry is the current secret, used for new data. Keep older versions in the list for as long as you need to read data written with them. Versions are non-negative integers and must be unique. Use at least 32 characters per secret.
BETTER_AUTH_SECRET itself must stay set. The app also reads it directly to sign the older desktop device tokens and mail unsubscribe links, so changing its value invalidates those; users of the desktop app then sign in again.
ENCRYPTION_KEY is a separate key (it protects integration credentials) and is not affected by this rotation. Back both up.