Compare commits

..

3 Commits

Author SHA1 Message Date
Balázs Orbán
079fbd27fa update in core 2022-12-31 08:51:19 +01:00
Balázs Orbán
c7101981bc Merge branch 'main' into fix/callbackJwtDocstringUpdate 2022-12-31 08:49:40 +01:00
=
f7b052a5fd fix(core): update CallbacksOptions.jwt docstring
Change description to reflect that JWT is encrypted by default
2022-11-15 19:43:39 +01:00
2 changed files with 7 additions and 10 deletions

View File

@@ -41,7 +41,6 @@ import { EncryptJWT, jwtDecrypt } from "jose"
import { SessionStore } from "./lib/cookie.js"
import { Awaitable } from "./types.js"
import type { LoggerInstance } from "./lib/utils/logger.js"
import { MissingSecret } from "./errors.js"
const DEFAULT_MAX_AGE = 30 * 24 * 60 * 60 // 30 days
@@ -98,16 +97,13 @@ export interface GetTokenParams<R extends boolean = false> {
}
/**
* Takes an Auth.js request (`req`) and returns either the Auth.js issued JWT's payload,
* Takes a Auth.js request (`req`) and returns either the Auth.js issued JWT's payload,
* or the raw JWT string. We look for the JWT in the either the cookies, or the `Authorization` header.
* [Documentation](https://authjs.dev/guides/basics/securing-pages-and-api-routes#using-gettoken)
*/
export async function getToken<R extends boolean = false>(
params: GetTokenParams<R>
): Promise<R extends true ? string : JWT | null>
export async function getToken(
params: GetTokenParams
): Promise<string | JWT | null> {
): Promise<R extends true ? string : JWT | null> {
const {
req,
secureCookie = process.env.NEXTAUTH_URL?.startsWith("https://") ??
@@ -122,8 +118,6 @@ export async function getToken(
} = params
if (!req) throw new Error("Must pass `req` to JWT getToken()")
if (!secret)
throw new MissingSecret("Must pass `secret` if not set to JWT getToken()")
const sessionStore = new SessionStore(
{ name: cookieName, options: { secure: secureCookie } },
@@ -144,13 +138,17 @@ export async function getToken(
token = decodeURIComponent(urlEncodedToken)
}
// @ts-expect-error
if (!token) return null
// @ts-expect-error
if (raw) return token
try {
// @ts-expect-error
return await _decode({ token, secret })
} catch {
// @ts-expect-error
return null
}
}

View File

@@ -2,7 +2,6 @@ import type { OAuthConfig, OAuthUserConfig } from "./index.js"
export type DateTime = string
export type Gender = "female" | "male"
export type Birthday = "SOLAR" | "LUNAR"
export type AgeRange =
| "1-9"
| "10-14"
@@ -56,7 +55,7 @@ export interface KakaoProfile extends Record<string, any> {
birthyear?: string
birthday_needs_agreement?: boolean
birthday?: string
birthday_type?: Birthday
birthday_type?: string
gender_needs_agreement?: boolean
gender?: Gender
phone_number_needs_agreement?: boolean