Documentation

Troubleshooting

Common Motoko Base issues and fixes — auth, OAuth, database, email, billing, storage, Sentry, and build failures.

Open inChatGPT (opens in a new tab)Claude (opens in a new tab)Cursor (opens in a new tab)Common Motoko Base issues and fixes — auth, OAuth, database, email, billing, storage, Sentry, and build failures.

Quick fixes for problems that often appear during first setup or production deploy. For env details see Environment Variables.

Authentication doesn't work

Symptoms: Cannot sign in, session lost on refresh, redirect loops, cookies not set.

CheckFix
BETTER_AUTH_SECRET missingSet in .env — required in production
BETTER_AUTH_URL wrongMust match the URL you open in the browser (including http:// vs https://, port, no trailing slash issues)
Mismatch with NEXT_PUBLIC_APP_URLAlign both to the same origin in each environment
Database down / migrations not runVerify DATABASE_URL, run pnpm db:migrate
Email not verifiedDashboard requires verification — check inbox or use /verify-email

See Better Auth and Installation.

OAuth callback error

Symptoms: redirect_uri_mismatch, Google/GitHub error after authorize, social buttons disabled.

CheckFix
Button disabledSet both GOOGLE_CLIENT_ID + GOOGLE_CLIENT_SECRET (or GitHub pair); restart dev server
Callback URL mismatchProvider console must have exactly {BETTER_AUTH_URL}/api/auth/callback/google or .../github
Production vs localAdd separate callback URLs for localhost and production domain
Google testing modeAdd your account as a test user on the OAuth consent screen

See OAuth Setup.

Database connection failed

Symptoms: App crashes on boot, migrations fail, ECONNREFUSED, timeout errors.

CheckFix
DATABASE_URL unset or wrongCopy from Supabase/host dashboard; never use NEXT_PUBLIC_*
Migrations not appliedpnpm db:migrate
Pooler vs directRuntime: transaction pooler (often port 6543). Migrations: try direct URL (port 5432) if DDL fails
Supabase paused projectRestore project in Supabase dashboard
prepare: falseAlready set in src/lib/db/index.ts — required for Supabase pooler; do not enable prepared statements

See Database and Migrations.

Emails aren't being sent

Symptoms: No verification email after sign-up, forgot-password does nothing, welcome email missing.

CheckFix
Resend not configuredSet RESEND_API_KEY and EMAIL_FROM
Wrong senderUse verified domain in production; for tests try onboarding@resend.dev
BETTER_AUTH_URL wrongReset/verification links point to wrong host — fix origin
Forgot-password page errorPage checks isEmailConfigured() — both Resend vars required
Resend dashboardCheck Resend logs for bounces or API errors

See Email (Resend).

Polar checkout doesn't open

Symptoms: Billing page shows “not configured”, checkout button fails, stays on Free after payment.

CheckFix
Missing env varsPOLAR_ACCESS_TOKEN, POLAR_PRO_MONTHLY_PRODUCT_ID, POLAR_WEBHOOK_SECRET
Sandbox vs productionPOLAR_SERVER=sandbox with sandbox token/product — or production with live credentials
Webhook URL{APP_URL}/api/billing/webhooks/polar — must be reachable from Polar
After checkoutBilling page uses getFreshBillingSummary on success redirect; confirm webhook delivered
No Polar customerUser needs a Polar customer (created on sign-up when billing configured) before portal

See Payments (Polar).

R2 upload fails

Symptoms: Storage page shows config message, presigned URL error, browser upload CORS failure, 403 on PUT.

CheckFix
Missing R2_* varsSet account ID, access key, secret, bucket name
Bucket name with slashmy-bucket/demo → bucket my-bucket, prefix demo/ — or use R2_PREFIX
CORSAdd your app origin to R2 bucket CORS policy in Cloudflare
File too large / wrong MIMELimits in src/features/storage/config.ts
HEAD validation failsServer validates upload after PUT — check object exists in R2 dashboard

See Storage (R2).

Sentry isn't receiving errors

Symptoms: No issues in Sentry dashboard after throwing a test error.

CheckFix
Testing in next devSentry is disabled during dev — use pnpm build && pnpm start or test on deployed production
DSN unsetSet NEXT_PUBLIC_SENTRY_DSN
Wrong projectConfirm DSN matches the Sentry project you are viewing
Ad blockersBrowser may block Sentry — try /sentry-tunnel route or test server-side error
Source mapsSet SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT at build time for readable stacks

See Monitoring (Sentry).

Build fails

Symptoms: pnpm build exits with errors locally or in CI.

CheckFix
Node versionRequires Node ≥ 22 — run node -v
Type errorspnpm typecheck — fix reported TypeScript issues
Lint errorspnpm lint
Missing env at buildMost vars are runtime-only; Sentry upload vars needed only if using source maps
MDX / docsRun pnpm install so postinstall (fumadocs-mdx) completes
LockfileUse pnpm install — do not mix npm/yarn
pnpm lint && pnpm typecheck && pnpm test && pnpm build

Still stuck?

  1. Re-read Installation and Production Setup
  2. Compare your .env against .env.example
  3. Check integration dashboards (Resend, Polar, Cloudflare, PostHog, Sentry)
  4. Search the repo README, docs/style-guide/ (maintainer-facing coding conventions), and feature READMEs under src/lib/email/, src/lib/security/, etc.

Scripts — Command reference.

Configuration Reference — Config file index.

Maintainer style guide — Internal coding conventions for agents and contributors live in docs/style-guide/ at the repository root (not part of the public docs site).