Skip to content

Commit 8115a7c

Browse files
committed
Add option to get raw JWT from getToken helper
1 parent 1ab029c commit 8115a7c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next-auth",
3-
"version": "3.0.0-beta.25",
3+
"version": "3.0.0-beta.26",
44
"description": "Authentication for Next.js",
55
"homepage": "https://next-auth.js.org",
66
"repository": "https://github.com/iaincollins/next-auth.git",

src/lib/jwt.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ const getToken = async (args) => {
9797
// Use secure prefix for cookie name, unless URL is NEXTAUTH_URL is http://
9898
// or not set (e.g. development or test instance) case use unprefixed name
9999
secureCookie = !(!process.env.NEXTAUTH_URL || process.env.NEXTAUTH_URL.startsWith('http://')),
100-
cookieName = (secureCookie) ? '__Secure-next-auth.session-token' : 'next-auth.session-token'
100+
cookieName = (secureCookie) ? '__Secure-next-auth.session-token' : 'next-auth.session-token',
101+
raw = false
101102
} = args
102103
if (!req) throw new Error('Must pass `req` to JWT getToken()')
103104

@@ -112,6 +113,10 @@ const getToken = async (args) => {
112113
token = decodeURIComponent(urlEncodedToken)
113114
}
114115

116+
if (raw) {
117+
return token
118+
}
119+
115120
try {
116121
return await decode({ token, ...args })
117122
} catch (error) {

www/docs/configuration/options.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ It also supports the following options:
178178

179179
The `secureCookie` option is ignored if `cookieName` is explcitly specified.
180180

181+
* `raw` - (boolean) Get raw token (not decoded)
182+
183+
If set to `true` returns the raw token without decrypting or verifying it.
184+
181185
:::note
182186
The JWT is stored in the Session Token cookie, the same cookie used for tokens with database sessions.
183187
:::

0 commit comments

Comments
 (0)