Skip to content

Commit 490a033

Browse files
committed
fix: support AUTH_SECRET for compat with npx auth secret
1 parent 1e6be72 commit 490a033

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Diff for: packages/next-auth/src/jwt/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function getToken<R extends boolean = false>(
8080
raw,
8181
decode: _decode = decode,
8282
logger = console,
83-
secret = process.env.NEXTAUTH_SECRET,
83+
secret = process.env.NEXTAUTH_SECRET ?? process.env.AUTH_SECRET,
8484
} = params
8585

8686
if (!req) throw new Error("Must pass `req` to JWT getToken()")

Diff for: packages/next-auth/src/next/index.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ async function NextAuthApiHandler(
2727
) {
2828
const { nextauth, ...query } = req.query
2929

30-
options.secret ??= options.jwt?.secret ?? process.env.NEXTAUTH_SECRET
30+
options.secret ??=
31+
options.jwt?.secret ??
32+
process.env.NEXTAUTH_SECRET ??
33+
process.env.AUTH_SECRET
3134

3235
const handler = await AuthHandler({
3336
req: {
@@ -71,7 +74,7 @@ async function NextAuthRouteHandler(
7174
context: RouteHandlerContext,
7275
options: AuthOptions
7376
) {
74-
options.secret ??= process.env.NEXTAUTH_SECRET
77+
options.secret ??= process.env.NEXTAUTH_SECRET ?? process.env.AUTH_SECRET
7578

7679
// eslint-disable-next-line @typescript-eslint/no-var-requires
7780
const { headers, cookies } = require("next/headers")
@@ -175,7 +178,7 @@ export async function getServerSession<
175178
O extends GetServerSessionOptions,
176179
R = O["callbacks"] extends { session: (...args: any[]) => infer U }
177180
? U
178-
: Session,
181+
: Session
179182
>(...args: GetServerSessionParams<O>): Promise<R | null> {
180183
const isRSC = args.length === 0 || args.length === 1
181184

@@ -198,7 +201,7 @@ export async function getServerSession<
198201
options = Object.assign({}, args[2], { providers: [] })
199202
}
200203

201-
options.secret ??= process.env.NEXTAUTH_SECRET
204+
options.secret ??= process.env.NEXTAUTH_SECRET ?? process.env.AUTH_SECRET
202205

203206
const session = await AuthHandler<Session | {} | string>({
204207
options,
@@ -233,7 +236,7 @@ export async function unstable_getServerSession<
233236
O extends GetServerSessionOptions,
234237
R = O["callbacks"] extends { session: (...args: any[]) => infer U }
235238
? U
236-
: Session,
239+
: Session
237240
>(...args: GetServerSessionParams<O>): Promise<R | null> {
238241
if (!deprecatedWarningShown && process.env.NODE_ENV !== "production") {
239242
console.warn(
@@ -250,6 +253,8 @@ declare global {
250253
namespace NodeJS {
251254
interface ProcessEnv {
252255
NEXTAUTH_URL?: string
256+
NEXTAUTH_SECRET?: string
257+
AUTH_SECRET?: string
253258
VERCEL?: "1"
254259
}
255260
}

Diff for: packages/next-auth/src/next/middleware.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ async function handleMiddleware(
118118
return
119119
}
120120

121-
const secret = options?.secret ?? process.env.NEXTAUTH_SECRET
121+
const secret =
122+
options?.secret ?? process.env.NEXTAUTH_SECRET ?? process.env.AUTH_SECRET
122123
if (!secret) {
123124
console.error(
124125
`[next-auth][error][NO_SECRET]`,

0 commit comments

Comments
 (0)