Authentication

Core authentication utilities and hooks

The authentication registry provides a complete server-side auth flow with password sign-in, OAuth providers, persistent sessions, access/refresh tokens, and a React Query session provider.

The registry item auth installs the server core, built-in OAuth providers, auth configuration, and the client useSession hook. Database integrations are separate registry blocks for Drizzle, Prisma, and Mongoose.

What is included

The auth block contains:

  • createAuth and the request handlers.
  • Session and current-user helpers.
  • Password sign-in and sign-out.
  • Access-token verification and refresh.
  • OAuth provider implementations.
  • Cookie serialization and token lifecycle handling.
  • SessionProvider and useSession.

Registry items

Registry itemPurpose
authCore authentication runtime and React session provider.
auth-adapter-drizzleDrizzle ORM schema and adapter.
auth-adapter-prismaPrisma schema and adapter.
auth-adapter-mongooseMongoose schema and adapter.

Providers

The built-in OAuth providers are:

Google, Github, Discord, Facebook, Figma, and Vercel.

Each provider follows the same BaseProvider interface and maps the provider's user profile into the registry's OAuthAccount shape.

Security model

The server stores only a hash of the refresh-token secret. Refresh tokens are split into an ID and secret, while access tokens are signed JWTs. OAuth state and PKCE values are stored in short-lived cookies during the authorization flow.

Installation

The authentication system consists of the core auth package and an optional database adapter. Install auth first, then choose the adapter that matches your application's database layer.

npx shadcn add https://ui.tiesen.id.vn/r/auth.json

Database adapters

Database adapters connect the authentication layer to your persistence layer. Choose one adapter based on the database technology already used in your application.

Drizzle

Use the Drizzle adapter when your application uses Drizzle ORM. It provides the authentication schema and persistence operations for relational databases supported by your Drizzle setup.

npx shadcn add https://ui.tiesen.id.vn/r/auth-adapter-drizzle.json

Prisma

Use the Prisma adapter when your application uses Prisma ORM. The adapter integrates with your generated Prisma client and provides the models required by the authentication system.

npx shadcn add https://ui.tiesen.id.vn/r/auth-adapter-prisma.json

Mongoose

Use the Mongoose adapter when your application uses MongoDB with Mongoose. It provides the authentication models and persistence layer for users, accounts, and sessions.

npx shadcn add https://ui.tiesen.id.vn/r/auth-adapter-mongoose.json

You only need one database adapter. The authentication API remains the same regardless of which adapter you choose.

On this page