mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
Compare commits
7 Commits
fix/callba
...
fix/add-fu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44181750a5 | ||
|
|
eda557e147 | ||
|
|
d63166db3a | ||
|
|
f387793d71 | ||
|
|
8751c18f26 | ||
|
|
4752f5d6c4 | ||
|
|
7e7f018d3b |
@@ -41,6 +41,7 @@ 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
|
||||
|
||||
@@ -97,13 +98,16 @@ export interface GetTokenParams<R extends boolean = false> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a Auth.js request (`req`) and returns either the Auth.js issued JWT's payload,
|
||||
* Takes an 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> {
|
||||
): Promise<R extends true ? string : JWT | null>
|
||||
export async function getToken(
|
||||
params: GetTokenParams
|
||||
): Promise<string | JWT | null> {
|
||||
const {
|
||||
req,
|
||||
secureCookie = process.env.NEXTAUTH_URL?.startsWith("https://") ??
|
||||
@@ -118,6 +122,8 @@ export async function getToken<R extends boolean = false>(
|
||||
} = 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 } },
|
||||
@@ -138,17 +144,13 @@ export async function getToken<R extends boolean = false>(
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ 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"
|
||||
@@ -55,7 +56,7 @@ export interface KakaoProfile extends Record<string, any> {
|
||||
birthyear?: string
|
||||
birthday_needs_agreement?: boolean
|
||||
birthday?: string
|
||||
birthday_type?: string
|
||||
birthday_type?: Birthday
|
||||
gender_needs_agreement?: boolean
|
||||
gender?: Gender
|
||||
phone_number_needs_agreement?: boolean
|
||||
|
||||
@@ -202,9 +202,9 @@ export interface CallbacksOptions<P = Profile, A = Account> {
|
||||
* or updated (i.e whenever a session is accessed in the client).
|
||||
* Its content is forwarded to the `session` callback,
|
||||
* where you can control what should be returned to the client.
|
||||
* Anything else will be kept from your front-end.
|
||||
* Anything else will be kept inaccessible from the client.
|
||||
*
|
||||
* ⚠ By default the JWT is signed, but not encrypted.
|
||||
* By default the JWT is encrypted.
|
||||
*
|
||||
* [Documentation](https://authjs.dev/guides/basics/callbacks#jwt-callback) |
|
||||
* [`session` callback](https://authjs.dev/guides/basics/callbacks#session-callback)
|
||||
|
||||
Reference in New Issue
Block a user