Timify delegates all authentication to better-auth, a framework-agnostic auth library with first-class Next.js support. The server-side auth instance lives inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Aking16/timify/llms.txt
Use this file to discover all available pages before exploring further.
src/lib/auth.ts and handles session creation, validation, and cookie management. A lightweight client wrapper in src/lib/auth-client.ts exposes auth methods to React client components.
How Authentication Is Configured
The auth instance is initialized with a Drizzle adapter pointing at the SQLite database, email/password sign-in, a localization plugin, and several advanced cookie settings:src/lib/auth.ts
Environment Variables
Two environment variables drive the auth configuration. Both must be set before starting the app.A secret string used to sign session tokens. Any token signed with a
different secret (or a rotated secret) will be rejected, invalidating all
existing sessions.
The fully-qualified base URL of the application. better-auth uses this to
populate the
trustedOrigins list and to build absolute callback URLs. It
must match the URL that browsers use to reach the app.Auth API Route
The better-auth request handler is mounted at/api/auth/[...all] via Next.js route handlers. All sign-in, sign-out, and session API calls are routed through here:
src/app/api/auth/[...all]/route.ts
Auth Client
Client components importauthClient from src/lib/auth-client.ts to call auth methods (sign-in, sign-out, sign-up) without directly touching the server:
src/lib/auth-client.ts
authClient exposes reactive hooks and async methods such as authClient.signIn.email(), authClient.signUp.email(), and authClient.signOut().
Session Management
Sessions are stored in thesession table in the SQLite database (see Database for the schema). Each session row contains the user ID, an expiry timestamp, IP address, and user-agent.
The requireSession() server function in src/lib/auth-guard.ts is the primary way server components and route handlers enforce authentication:
src/lib/auth-guard.ts
requireSession() at the top of any Server Component or Server Action that requires the user to be logged in. It returns the full session object on success, or redirects to /auth if no valid session exists.
Auth Routes
| Route | Purpose |
|---|---|
/auth | Login page (default tab) |
/auth?tab=register | Registration page |
/api/auth/[...all] | better-auth internal API handler |
defaultRoutes constants in src/constants/routes.ts drive navigation throughout the app:
src/constants/routes.ts
handleLogout() in src/lib/auth-libs.ts, which calls authClient.signOut() and redirects to / on success:
src/lib/auth-libs.ts
Cookie Configuration
Cross-subdomain cookies
Cross-subdomain cookies
Secure cookies (production)
Secure cookies (production)
Localization
Thebetter-auth-localization plugin is registered with defaultLocale: "fa-IR" (Persian / Farsi). This localizes built-in better-auth error messages and UI strings to Persian:
"fa-IR" with the desired BCP 47 language tag supported by better-auth-localization.
Trusted Origins
ThetrustedOrigins list controls which origins are allowed to make authenticated requests to the better-auth API. It is pre-populated with BETTER_AUTH_URL and a local LAN address for development convenience:
In production, make sure
BETTER_AUTH_URL is set to your public domain. You
can remove the LAN address entry or add additional origins as needed for your
deployment topology.Production Checklist
Set a strong BETTER_AUTH_SECRET
Generate a cryptographically random secret and add it to your production
environment:
Enable secure cookies
In
src/lib/auth.ts, set useSecureCookies: true so session cookies are
only transmitted over HTTPS.