Concepts, value, and typical clone scenarios — less code.
Concepts, value, and typical clone scenarios — less code.
Підготовка контенту платформи Ring
Підготовка контенту платформи Ring
Підготовка контенту платформи Ring
Ring Platform uses Auth.js v5 (NextAuth) with a JWT session strategy. The adapter (PostgreSQL or Firebase) is selected by DB_BACKEND_MODE.
Use Founder / Developer tabs in the docs sidebar to filter by audience.
| Provider | Flow | Auth.js provider |
|---|---|---|
| Google OAuth | Full OAuth 2.0 redirect + Google Identity Services (GIS) One Tap | GoogleProvider + CredentialsProvider("google-one-tap") |
| Telegram (web) | OIDC Authorization Code + PKCE (oauth.telegram.org) | Custom TelegramOidcProvider (id: "telegram") when env set |
| Telegram Mini App | WebApp initData HMAC (WebAppData secret) | CredentialsProvider("telegram-miniapp") |
| Apple Sign-In | OAuth redirect, native iOS/macOS | AppleProvider |
| Ring Mailer | OTP + magic link / verify / reset via own SMTP (lib/mailer.ts) | Credentials email-otp / email-magic / credentials |
| Crypto Wallet | Nonce-signature verification (MetaMask, WalletConnect) | CredentialsProvider("crypto-wallet") |
Configuration lives in auth.ts and auth.config.ts at the project root. Auth.js v5 splits edge-safe config (auth.config.ts — no providers, minimal callbacks) from full server config (auth.ts — all providers, database adapters).
Product overview and BotFather checklist: Authentication.
Auth.js v5 manages the entire authentication flow — the platform does not use Firebase Auth directly. Firebase Admin SDK is used only for server-side token verification and user document lookups in firebase-full mode.
Session flow:
DB_BACKEND_MODE is PostgreSQL-basedDB_BACKEND_MODE=firebase-fullKey design decisions:
users.id), never Google sub, Apple sub, or Telegram id alone as the session primary keyPrerequisite: product overview, BotFather checklist, Mini App, and Telegram surface boundary.
Next-step: integrator snippets for OIDC and telegram-miniapp Credentials.
Depends-on: how DB_BACKEND_MODE picks the Auth.js adapter.
Same-workflow: complete AUTH_* and SMTP env blocks for clones.
Ring Platform uses Auth.js v5 (NextAuth) with a JWT session strategy. The adapter (PostgreSQL or Firebase) is selected by DB_BACKEND_MODE.
Use Founder / Developer tabs in the docs sidebar to filter by audience.
| Provider | Flow | Auth.js provider |
|---|---|---|
| Google OAuth | Full OAuth 2.0 redirect + Google Identity Services (GIS) One Tap | GoogleProvider + CredentialsProvider("google-one-tap") |
| Telegram (web) | OIDC Authorization Code + PKCE (oauth.telegram.org) | Custom TelegramOidcProvider (id: "telegram") when env set |
| Telegram Mini App | WebApp initData HMAC (WebAppData secret) | CredentialsProvider("telegram-miniapp") |
| Apple Sign-In | OAuth redirect, native iOS/macOS | AppleProvider |
| Ring Mailer | OTP + magic link / verify / reset via own SMTP (lib/mailer.ts) | Credentials email-otp / email-magic / credentials |
| Crypto Wallet | Nonce-signature verification (MetaMask, WalletConnect) | CredentialsProvider("crypto-wallet") |
Configuration lives in auth.ts and auth.config.ts at the project root. Auth.js v5 splits edge-safe config (auth.config.ts — no providers, minimal callbacks) from full server config (auth.ts — all providers, database adapters).
Product overview and BotFather checklist: Authentication.
Auth.js v5 manages the entire authentication flow — the platform does not use Firebase Auth directly. Firebase Admin SDK is used only for server-side token verification and user document lookups in firebase-full mode.
Session flow:
DB_BACKEND_MODE is PostgreSQL-basedDB_BACKEND_MODE=firebase-fullKey design decisions:
users.id), never Google sub, Apple sub, or Telegram id alone as the session primary keyPrerequisite: product overview, BotFather checklist, Mini App, and Telegram surface boundary.
Next-step: integrator snippets for OIDC and telegram-miniapp Credentials.
Depends-on: how DB_BACKEND_MODE picks the Auth.js adapter.
Same-workflow: complete AUTH_* and SMTP env blocks for clones.
Ring Platform uses Auth.js v5 (NextAuth) with a JWT session strategy. The adapter (PostgreSQL or Firebase) is selected by DB_BACKEND_MODE.
Use Founder / Developer tabs in the docs sidebar to filter by audience.
| Provider | Flow | Auth.js provider |
|---|---|---|
| Google OAuth | Full OAuth 2.0 redirect + Google Identity Services (GIS) One Tap | GoogleProvider + CredentialsProvider("google-one-tap") |
| Telegram (web) | OIDC Authorization Code + PKCE (oauth.telegram.org) | Custom TelegramOidcProvider (id: "telegram") when env set |
| Telegram Mini App | WebApp initData HMAC (WebAppData secret) | CredentialsProvider("telegram-miniapp") |
| Apple Sign-In | OAuth redirect, native iOS/macOS | AppleProvider |
| Ring Mailer | OTP + magic link / verify / reset via own SMTP (lib/mailer.ts) | Credentials email-otp / email-magic / credentials |
| Crypto Wallet | Nonce-signature verification (MetaMask, WalletConnect) | CredentialsProvider("crypto-wallet") |
Configuration lives in auth.ts and auth.config.ts at the project root. Auth.js v5 splits edge-safe config (auth.config.ts — no providers, minimal callbacks) from full server config (auth.ts — all providers, database adapters).
Product overview and BotFather checklist: Authentication.
Auth.js v5 manages the entire authentication flow — the platform does not use Firebase Auth directly. Firebase Admin SDK is used only for server-side token verification and user document lookups in firebase-full mode.
Session flow:
DB_BACKEND_MODE is PostgreSQL-basedDB_BACKEND_MODE=firebase-fullKey design decisions:
users.id), never Google sub, Apple sub, or Telegram id alone as the session primary keyPrerequisite: product overview, BotFather checklist, Mini App, and Telegram surface boundary.
Next-step: integrator snippets for OIDC and telegram-miniapp Credentials.
Depends-on: how DB_BACKEND_MODE picks the Auth.js adapter.
Same-workflow: complete AUTH_* and SMTP env blocks for clones.
SHA256(bot_token)isTelegramMiniAppAuthDateFresh — default max age 86400 secondsresolveOrCreateTelegramUser with Telegram id / name / username / photo from parsed user JSONClient shape: signIn('telegram-miniapp', { initData, redirect: false }). Tests: __tests__/auth/telegram-miniapp-initdata.test.ts.
Own SMTP via lib/mailer.ts. Tokens live in Postgres email_login_tokens (migration 038). Magic links use hash URLs (/verify#token=…) and are consumed only in Credentials authorize — never on GET.
Server Actions: app/_actions/auth-email-actions.ts. Full setup: Ring Mailer.
Nonce-based signature verification via Viem. Supports Ethereum, Polygon, Arbitrum, Optimism, and Base:
The adapter is determined by DB_BACKEND_MODE:
| Mode | Adapter | Source |
|---|---|---|
k8s-postgres-fcm | PostgreSQLAdapter | lib/auth/postgres-adapter.ts |
firebase-full | FirestoreAdapter from @auth/firebase-adapter | via getAdminDb() |
supabase-fcm | PostgreSQLAdapter | Same PostgreSQL path |
Firebase Admin SDK is used in two contexts:
firebase-full mode only): FirestoreAdapter reads/writes user documentsdb().readDoc('users', storageId) for nonce lookup (BackendSelector routes Firebase or PostgreSQL)In k8s-postgres-fcm and supabase-fcm modes, getAdminDb() returns a mock Firestore — no real Firebase init happens. FCM push messaging still uses Firebase Admin through firebase-admin.server.ts (separate from the auth path).
See-also: admin bot whitelist — not member OIDC or Mini App Login.
auth.config.ts — Edge-compatible config (empty providers, authorized callback, redirects)
auth.ts — Full server config (all providers, database adapter, JWT/session callbacks)
lib/auth-adapter-singleton.ts — Cached adapter: PostgreSQLAdapter or FirestoreAdapter
lib/auth/postgres-adapter.ts — Custom PostgreSQL adapter for Auth.js v5
lib/auth/telegram-oidc.ts — Telegram OIDC provider + claim helpers
lib/auth/telegram-miniapp-initdata.ts — Mini App WebAppData HMAC + getTelegramMiniAppBotToken
lib/auth/telegram-login-widget-hash.ts — Legacy Login Widget HMAC
lib/firebase-admin.server.ts — Firebase Admin SDK instance (getAdminAuth, getAdminDb)
app/api/auth/[...nextauth]/route.ts — Auth.js API route handler
app/api/auth/telegram/callback/route.ts — Session-required profile linking (widget)
# Auth.js core
AUTH_SECRET=your_auth_secret
AUTH_TRUST_HOST=true
# Google OAuth
AUTH_GOOGLE_ID=your_google_client_id
AUTH_GOOGLE_SECRET=your_google_client_secret
# Telegram Web Login OIDC (BotFather → Web Login)
AUTH_TELEGRAM_ID=your_telegram_oidc_client_id
AUTH_TELEGRAM_SECRET=your_telegram_oidc_client_secret
# ADMIN_BOT_TOKEN=... # Login Widget hash / admin bot API
# TELEGRAM_MINI_APP_BOT_TOKEN=... # Mini App initData HMAC (+ Stars invoices)
# Apple Sign-In
AUTH_APPLE_ID=your_apple_client_id
AUTH_APPLE_SECRET=your_apple_private_key
# Ring Mailer (no AUTH_RESEND_*)
# EMAIL_MODE=ethereal
# SMTP_HOST= / SMTP_USER= / SMTP_PASSWORD= / SMTP_FROM=
# OTP_HMAC_SECRET=
# Firebase (for firebase-full mode only)
AUTH_FIREBASE_PROJECT_ID=your_firebase_project_id
AUTH_FIREBASE_CLIENT_EMAIL=your_firebase_client_email
AUTH_FIREBASE_PRIVATE_KEY=your_firebase_private_key
# WalletConnect
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_idSHA256(bot_token)isTelegramMiniAppAuthDateFresh — default max age 86400 secondsresolveOrCreateTelegramUser with Telegram id / name / username / photo from parsed user JSONClient shape: signIn('telegram-miniapp', { initData, redirect: false }). Tests: __tests__/auth/telegram-miniapp-initdata.test.ts.
Own SMTP via lib/mailer.ts. Tokens live in Postgres email_login_tokens (migration 038). Magic links use hash URLs (/verify#token=…) and are consumed only in Credentials authorize — never on GET.
Server Actions: app/_actions/auth-email-actions.ts. Full setup: Ring Mailer.
Nonce-based signature verification via Viem. Supports Ethereum, Polygon, Arbitrum, Optimism, and Base:
The adapter is determined by DB_BACKEND_MODE:
| Mode | Adapter | Source |
|---|---|---|
k8s-postgres-fcm | PostgreSQLAdapter | lib/auth/postgres-adapter.ts |
firebase-full | FirestoreAdapter from @auth/firebase-adapter | via getAdminDb() |
supabase-fcm | PostgreSQLAdapter | Same PostgreSQL path |
Firebase Admin SDK is used in two contexts:
firebase-full mode only): FirestoreAdapter reads/writes user documentsdb().readDoc('users', storageId) for nonce lookup (BackendSelector routes Firebase or PostgreSQL)In k8s-postgres-fcm and supabase-fcm modes, getAdminDb() returns a mock Firestore — no real Firebase init happens. FCM push messaging still uses Firebase Admin through firebase-admin.server.ts (separate from the auth path).
See-also: admin bot whitelist — not member OIDC or Mini App Login.
auth.config.ts — Edge-compatible config (empty providers, authorized callback, redirects)
auth.ts — Full server config (all providers, database adapter, JWT/session callbacks)
lib/auth-adapter-singleton.ts — Cached adapter: PostgreSQLAdapter or FirestoreAdapter
lib/auth/postgres-adapter.ts — Custom PostgreSQL adapter for Auth.js v5
lib/auth/telegram-oidc.ts — Telegram OIDC provider + claim helpers
lib/auth/telegram-miniapp-initdata.ts — Mini App WebAppData HMAC + getTelegramMiniAppBotToken
lib/auth/telegram-login-widget-hash.ts — Legacy Login Widget HMAC
lib/firebase-admin.server.ts — Firebase Admin SDK instance (getAdminAuth, getAdminDb)
app/api/auth/[...nextauth]/route.ts — Auth.js API route handler
app/api/auth/telegram/callback/route.ts — Session-required profile linking (widget)
# Auth.js core
AUTH_SECRET=your_auth_secret
AUTH_TRUST_HOST=true
# Google OAuth
AUTH_GOOGLE_ID=your_google_client_id
AUTH_GOOGLE_SECRET=your_google_client_secret
# Telegram Web Login OIDC (BotFather → Web Login)
AUTH_TELEGRAM_ID=your_telegram_oidc_client_id
AUTH_TELEGRAM_SECRET=your_telegram_oidc_client_secret
# ADMIN_BOT_TOKEN=... # Login Widget hash / admin bot API
# TELEGRAM_MINI_APP_BOT_TOKEN=... # Mini App initData HMAC (+ Stars invoices)
# Apple Sign-In
AUTH_APPLE_ID=your_apple_client_id
AUTH_APPLE_SECRET=your_apple_private_key
# Ring Mailer (no AUTH_RESEND_*)
# EMAIL_MODE=ethereal
# SMTP_HOST= / SMTP_USER= / SMTP_PASSWORD= / SMTP_FROM=
# OTP_HMAC_SECRET=
# Firebase (for firebase-full mode only)
AUTH_FIREBASE_PROJECT_ID=your_firebase_project_id
AUTH_FIREBASE_CLIENT_EMAIL=your_firebase_client_email
AUTH_FIREBASE_PRIVATE_KEY=your_firebase_private_key
# WalletConnect
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_idSHA256(bot_token)isTelegramMiniAppAuthDateFresh — default max age 86400 secondsresolveOrCreateTelegramUser with Telegram id / name / username / photo from parsed user JSONClient shape: signIn('telegram-miniapp', { initData, redirect: false }). Tests: __tests__/auth/telegram-miniapp-initdata.test.ts.
Own SMTP via lib/mailer.ts. Tokens live in Postgres email_login_tokens (migration 038). Magic links use hash URLs (/verify#token=…) and are consumed only in Credentials authorize — never on GET.
Server Actions: app/_actions/auth-email-actions.ts. Full setup: Ring Mailer.
Nonce-based signature verification via Viem. Supports Ethereum, Polygon, Arbitrum, Optimism, and Base:
The adapter is determined by DB_BACKEND_MODE:
| Mode | Adapter | Source |
|---|---|---|
k8s-postgres-fcm | PostgreSQLAdapter | lib/auth/postgres-adapter.ts |
firebase-full | FirestoreAdapter from @auth/firebase-adapter | via getAdminDb() |
supabase-fcm | PostgreSQLAdapter | Same PostgreSQL path |
Firebase Admin SDK is used in two contexts:
firebase-full mode only): FirestoreAdapter reads/writes user documentsdb().readDoc('users', storageId) for nonce lookup (BackendSelector routes Firebase or PostgreSQL)In k8s-postgres-fcm and supabase-fcm modes, getAdminDb() returns a mock Firestore — no real Firebase init happens. FCM push messaging still uses Firebase Admin through firebase-admin.server.ts (separate from the auth path).
See-also: admin bot whitelist — not member OIDC or Mini App Login.
auth.config.ts — Edge-compatible config (empty providers, authorized callback, redirects)
auth.ts — Full server config (all providers, database adapter, JWT/session callbacks)
lib/auth-adapter-singleton.ts — Cached adapter: PostgreSQLAdapter or FirestoreAdapter
lib/auth/postgres-adapter.ts — Custom PostgreSQL adapter for Auth.js v5
lib/auth/telegram-oidc.ts — Telegram OIDC provider + claim helpers
lib/auth/telegram-miniapp-initdata.ts — Mini App WebAppData HMAC + getTelegramMiniAppBotToken
lib/auth/telegram-login-widget-hash.ts — Legacy Login Widget HMAC
lib/firebase-admin.server.ts — Firebase Admin SDK instance (getAdminAuth, getAdminDb)
app/api/auth/[...nextauth]/route.ts — Auth.js API route handler
app/api/auth/telegram/callback/route.ts — Session-required profile linking (widget)
# Auth.js core
AUTH_SECRET=your_auth_secret
AUTH_TRUST_HOST=true
# Google OAuth
AUTH_GOOGLE_ID=your_google_client_id
AUTH_GOOGLE_SECRET=your_google_client_secret
# Telegram Web Login OIDC (BotFather → Web Login)
AUTH_TELEGRAM_ID=your_telegram_oidc_client_id
AUTH_TELEGRAM_SECRET=your_telegram_oidc_client_secret
# ADMIN_BOT_TOKEN=... # Login Widget hash / admin bot API
# TELEGRAM_MINI_APP_BOT_TOKEN=... # Mini App initData HMAC (+ Stars invoices)
# Apple Sign-In
AUTH_APPLE_ID=your_apple_client_id
AUTH_APPLE_SECRET=your_apple_private_key
# Ring Mailer (no AUTH_RESEND_*)
# EMAIL_MODE=ethereal
# SMTP_HOST= / SMTP_USER= / SMTP_PASSWORD= / SMTP_FROM=
# OTP_HMAC_SECRET=
# Firebase (for firebase-full mode only)
AUTH_FIREBASE_PROJECT_ID=your_firebase_project_id
AUTH_FIREBASE_CLIENT_EMAIL=your_firebase_client_email
AUTH_FIREBASE_PRIVATE_KEY=your_firebase_private_key
# WalletConnect
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=your_project_id