Skip to content

Commit

Permalink
Add option to get raw JWT from getToken helper
Browse files Browse the repository at this point in the history
  • Loading branch information
iaincollins committed Jul 27, 2020
1 parent 1ab029c commit 8115a7c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-auth",
"version": "3.0.0-beta.25",
"version": "3.0.0-beta.26",
"description": "Authentication for Next.js",
"homepage": "https://next-auth.js.org",
"repository": "https://github.com/iaincollins/next-auth.git",
Expand Down
7 changes: 6 additions & 1 deletion src/lib/jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ const getToken = async (args) => {
// Use secure prefix for cookie name, unless URL is NEXTAUTH_URL is http://
// or not set (e.g. development or test instance) case use unprefixed name
secureCookie = !(!process.env.NEXTAUTH_URL || process.env.NEXTAUTH_URL.startsWith('http://')),
cookieName = (secureCookie) ? '__Secure-next-auth.session-token' : 'next-auth.session-token'
cookieName = (secureCookie) ? '__Secure-next-auth.session-token' : 'next-auth.session-token',
raw = false
} = args
if (!req) throw new Error('Must pass `req` to JWT getToken()')

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

if (raw) {
return token
}

try {
return await decode({ token, ...args })
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions www/docs/configuration/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ It also supports the following options:

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

* `raw` - (boolean) Get raw token (not decoded)

If set to `true` returns the raw token without decrypting or verifying it.

:::note
The JWT is stored in the Session Token cookie, the same cookie used for tokens with database sessions.
:::
Expand Down

0 comments on commit 8115a7c

Please sign in to comment.