packages/api/.dev.vars.example and the executable callbacks/webhook routes in packages/api/src/worker.ts.
Account authentication
Factorize owns authentication in PostgreSQL. Create a native account at/auth/signup with an email address and a password of 12–200 characters. Emails are case-insensitive. Verify the email before signing in at /auth/login; email plus password are accepted. Linear is connected after sign-in from Integrations, only for Linear-backed triggers.
Postmark sends one-hour, single-use verification and password-reset links. /auth/verify/request resends verification; /auth/password-reset handles recovery. Links never appear in application responses or logs. Passwords use salted PBKDF2-SHA-256. Change password in the account menu requires the current password. Password reset, password change and sign-out invalidate existing sessions via membership session versions, including delegated API credentials.
Before deploying, configure POSTMARK_SERVER_TOKEN as a production GitHub environment secret. The deployment copies it to a Worker secret; the verified sender and transactional message stream are non-secret Worker vars in packages/api/wrangler.jsonc. For a manual Postmark preflight, set the following environment variables along with APP_ORIGIN:
APP_ORIGIN must be the canonical HTTPS origin, without a trailing slash. Run npm run auth:validate-email --workspace=factorize manually when needed: it checks the server token/stream with Postmark and sends one preflight email from/to the configured sender, rejecting unverified senders or sending failures. It prints no credentials. Missing configuration fails the manual check. The deploy workflow does not run this check or send a preflight email. Runtime signup and recovery also fail closed if configuration or delivery fails; users can resend verification after a delivery failure. Local mail testing needs an HTTPS origin and a separate Postmark test server/sender; automated tests mock Postmark and never send mail.
Optional Google sign-in
Create a Web application OAuth client in Google Cloud. Register exactly<APP_ORIGIN>/oauth/google/sign-in/callback as an authorized redirect URI
(https://app.factorize.sh/oauth/google/sign-in/callback on the hosted deployment).
Complete Google’s OAuth consent screen setup for your intended audience. Set
GOOGLE_SIGN_IN_CLIENT_ID and GOOGLE_SIGN_IN_CLIENT_SECRET as Worker secrets.
The Google button is hidden unless both values are set. Apply migration 0104
using the normal database deployment step. Google sign-in is separate from
Factorize’s MCP authorization clients and uses only openid email.
A first Google sign-in matching an existing verified Factorize account
requires its current Factorize password; email alone never links accounts.
New Google users choose a unique Factorize username. For addresses Google
does not manage directly, Factorize emails a confirmation link to be opened
in the browser that started signup. Once signed in, Google-first users can
use Set password. First confirm the linked Google account again, then open the
Factorize email link in that same browser. An email link alone cannot establish a
first password on a Google account.
Addresses verified independently by Factorize are not replaced by Google.
For accounts enrolled using Google’s authoritative email, Google remains the
authority for password recovery even after a password is added. Factorize
retires the old email’s recovery authority and outstanding links when a Google
address change is observed. If the new address needs independent confirmation,
prove it through the Google recovery flow. If it is already used by another
Factorize account, password recovery pauses rather than transferring or combining
accounts. Sign-in with the linked Google account still works. Keep Postmark
configured for address confirmation and password recovery.
Optional two-factor authentication
Two-factor authentication is off by default and configured by each user in Account settings → Two-factor authentication. There is no team enforcement. SetTOTP_ENCRYPTION_KEY as an independent Worker secret before offering
enrollment. Generate 32 cryptographically random bytes encoded as base64 (for
example, using openssl rand -base64 32). Do not reuse the credential encryption
key or store the value in the repository. Normal deployment applies migration
0105. Keep the key securely backed up; changing it without re-encrypting
existing TOTP secrets breaks authenticator verification for enrolled users.
Users with a saved recovery code can still sign in.
Enrollment requires confirmation of the current Factorize password, or fresh
Google confirmation for Google-only users. The setup QR code is generated in
the browser without sending the secret to a QR service. Users confirm a valid
authenticator code to enable 2FA and should immediately save the ten recovery
codes, which are shown once and work once each. Disabling requires primary
confirmation plus an authenticator or recovery code. Password reset does not
disable 2FA. Enable and disable invalidate older sessions and delegated grants
using existing membership session versions.
Existing account migration
Apply0008_native_accounts.sql and 0009_remove_auth_usernames.sql before deploying this code. They reject ambiguous legacy emails that differ only in case (reconcile those identities before retrying migration), preserve tenant IDs, memberships, triggers and encrypted Linear connections, and backfill explicit Linear organization-to-workspace mappings. Existing Linear-only users choose Forgot password or previously signed in with Linear?, receive a reset email at their existing address, and set a password. Email possession is required; signup cannot replace an existing account’s credentials. Existing native users keep their passwords and may sign in by email; unverified accounts must verify first. A reset never promotes a member to owner. An account with multiple existing owner memberships currently opens the oldest workspace; no new workspace-switching UI is introduced.
Linear OAuth requires an authenticated owner, binds state to that user/workspace, stores the connection there, and never creates a Factorize session. A Linear organization already bound to another workspace cannot be claimed. Existing webhook routes resolve the explicit mapping. Do not delete that binding to work around an account-recovery problem.
Authentication verification
npm run check runs unit/contract tests and Postmark preflight tests. CI also runs the real PostgreSQL authentication suite against a disposable service. To run it locally, set AUTH_TEST_DATABASE_URL to an isolated PostgreSQL server whose user can create/drop test databases, then run npm test --workspace=factorize -- --run test/native-auth.postgres.test.ts. The suite creates and removes its own database and applies every migration, including a legacy connection fixture before the auth migration.
Configure Cloudflare REST OAuth
Register a Cloudflare OAuth client using the authorization code and refresh token grants,client_secret_post, and the exact callback
<APP_ORIGIN>/oauth/cloudflare/callback. Verify the application domain and
promote the client to public if users outside your account need to connect.
Set CLOUDFLARE_OAUTH_CLIENT_ID, CLOUDFLARE_OAUTH_CLIENT_SECRET, and
CLOUDFLARE_OAUTH_DEFAULT_SCOPES on the Worker. Defaults are a space-separated
list of scope IDs registered on the Cloudflare client. If the new scope setting
is absent, Factorize uses the existing CLOUDFLARE_OAUTH_READ_SCOPES setting.
Factorize normalizes whitespace, removes duplicates, and sends those defaults
and the offline_access protocol scope. Cloudflare validates the requested IDs.
Changing or removing defaults only affects new connection attempts, not saved
grants. Code exchange and refresh still require the OAuth client credentials.
Cloudflare chooses the eligible accounts and lets users review requested
permissions and decline or re-enable optional ones. To offer additional
permissions, update both the Cloudflare client and the configured defaults;
the consent screen does not add unrequested scopes.
After authorizing on Cloudflare, use request_api with paths relative to the
Cloudflare v4 REST API (for example, /zones). Cloudflare enforces the scopes
and accounts in the token. Factorize applies its usual connection access
controls and keeps the credentials server-side. Earlier account-bound
connections require a fresh authorization before using this proxy; stored
connection rows are retained, and existing agent grants do not transfer.
Delete removes Factorize’s saved credentials; revoke the authorization on
Cloudflare to remove it there too.
Cloudflare Tail is retired. Old webhook endpoints return HTTP 410 and
Factorize no longer delivers Tail events. Historical configuration and Event
occurrences remain available for inspection or removal. The REST API integration
does not add log streaming or log triggers.
Configure Linear
Use authorization-code OAuth and enable Webhooks on the OAuth application. Configure:
After changing the webhook settings, re-authorize existing workspaces so Linear creates a fresh workspace subscription.
Configure ClickUp
Create a ClickUp OAuth application with the callback URLhttps://your-domain.example/auth/clickup/callback, then store its client ID and secret in CLICKUP_CLIENT_ID and CLICKUP_CLIENT_SECRET. Connecting ClickUp from Integrations registers the signed task webhook automatically. ClickUp events can filter a list by status, tag, assignee, or creator; all configured rules must match.
Configuration reference
Never commit
.dev.vars or production secret values. The included .dev.vars.example is a safe template.