Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Auth.js · Const

UpstashRedisAdapter

UpstashRedisAdapter connects Auth.js to Upstash Redis for adapter-backed persistence. It accepts a Redis client and optional key-prefix settings, then returns an Auth.js Adapter.

How it works

UpstashRedisAdapter accepts an Upstash Redis client and optionally a prefix-options object, then returns an Auth.js Adapter. Auth.js uses that adapter to persist authentication data in Upstash Redis; custom prefixes can separate multiple applications sharing one Redis instance.

Syntax

function UpstashRedisAdapter(client, options): Adapter

Parameters

NameTypeDescription
clientRedisUpstash Redis client used by the adapter.
optionsUpstashRedisAdapterOptionsOptional key-prefix configuration.

Returns

Adapter

Key points

  • This package is the official Upstash Redis integration for Auth.js and NextAuth.js.
  • The factory receives a Redis client and options, producing an Auth.js Adapter.
  • baseKeyPrefix provides a broad namespace prefix for stored keys.
  • accountKeyPrefix controls the prefix used for account keys.
  • sessionKeyPrefix controls the prefix used for session keys.
  • verificationTokenKeyPrefix controls the prefix used for verification-token keys.

Common mistakes

  • When using the free tier, multiple applications may share one Redis instance; configure distinct key prefixes for each application.
  • Pass the options object as the factory's second argument when overriding key prefixes.

Example: Configure Auth.js with Upstash Redis

import NextAuth from "next-auth"
import { UpstashRedisAdapter } from "@auth/upstash-redis-adapter"
import { Redis } from "@upstash/redis"

const redis = new Redis({
  url: process.env.UPSTASH_REDIS_URL!,
  token: process.env.UPSTASH_REDIS_TOKEN!,
})

export const { handlers, auth } = NextAuth({
  adapter: UpstashRedisAdapter(redis),
  providers: [],
})

Creates an Upstash Redis client and supplies it to Auth.js through the adapter factory.

When to use it

Persist Auth.js data in Upstash Redis

An Auth.js application needs database-backed users, accounts, sessions, or verification tokens in Upstash Redis.

Namespace multiple applications

Several Auth.js applications use one Upstash Redis instance.

Customize storage key prefixes

An application needs predictable Redis key organization.

Interview questions

QWhat does UpstashRedisAdapter return?

UpstashRedisAdapter is a factory that takes a Redis client and returns an Auth.js Adapter. The returned adapter connects Auth.js persistence operations to Upstash Redis.

Follow-up: How would you isolate two applications sharing Redis? Pass different prefix settings in the second argument for each adapter instance.

QWhat are the factory's parameters and return type?

The first argument is the Upstash Redis client, and the optional second argument contains UpstashRedisAdapterOptions. The function returns an Adapter.

Follow-up: Which option establishes a namespace for all keys? Use baseKeyPrefix, optionally combined with more specific key prefixes.

QWhat can the adapter options configure?

The adapter page documents prefixes for accounts, account lookups by user, email, sessions, sessions by user, users, and verification tokens. These prefixes control how related records are named in Redis.

Follow-up: Why are prefixes operationally useful? They prevent key collisions when applications share the same Redis instance.

  • UpstashRedisAdapterOptions
  • Adapter
  • Redis

Source: auth/upstash-redis-adapter - Auth.js. Checked 2026-10-15.