Skip to content

Commit 3744f56

Browse files
fix(getToken): make 'secret' optional when raw JWT is requested (#11894)
* fix(getToken): make 'secret' optional when raw JWT is requested * Update jwt.ts --------- Co-authored-by: Balázs Orbán <[email protected]>
1 parent e981d94 commit 3744f56

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/core/src/jwt.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export async function decode<Payload = JWT>(
108108
}
109109

110110
type GetTokenParamsBase = {
111-
secret: JWTDecodeParams["secret"]
111+
secret?: JWTDecodeParams["secret"]
112112
salt?: JWTDecodeParams["salt"]
113113
}
114114

@@ -155,8 +155,6 @@ export async function getToken(
155155
} = params
156156

157157
if (!req) throw new Error("Must pass `req` to JWT getToken()")
158-
if (!secret)
159-
throw new MissingSecret("Must pass `secret` if not set to JWT getToken()")
160158

161159
const headers =
162160
req.headers instanceof Headers ? req.headers : new Headers(req.headers)
@@ -180,6 +178,9 @@ export async function getToken(
180178

181179
if (raw) return token
182180

181+
if (!secret)
182+
throw new MissingSecret("Must pass `secret` if not set to JWT getToken()")
183+
183184
try {
184185
return await _decode({ token, secret, salt })
185186
} catch {

0 commit comments

Comments
 (0)