mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
Compare commits
7 Commits
next-auth@
...
next-auth@
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
494d16e54d | ||
|
|
5a8aa2e5e5 | ||
|
|
05ff6ae221 | ||
|
|
1fbc684f53 | ||
|
|
124be4fb1f | ||
|
|
3b0128c3ca | ||
|
|
36b97aafb8 |
@@ -159,7 +159,7 @@ Callbacks are asynchronous functions you can use to control what happens when an
|
|||||||
|
|
||||||
Specify URLs to be used if you want to create custom sign in, and error pages. Pages specified will override the corresponding built-in page.
|
Specify URLs to be used if you want to create custom sign in, and error pages. Pages specified will override the corresponding built-in page.
|
||||||
|
|
||||||
:::note
|
:::info
|
||||||
This should match the `pages` configuration that's found in `[...nextauth].ts`.
|
This should match the `pages` configuration that's found in `[...nextauth].ts`.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "next-auth",
|
"name": "next-auth",
|
||||||
"version": "4.22.4",
|
"version": "4.23.0",
|
||||||
"description": "Authentication for Next.js",
|
"description": "Authentication for Next.js",
|
||||||
"homepage": "https://next-auth.js.org",
|
"homepage": "https://next-auth.js.org",
|
||||||
"repository": "https://github.com/nextauthjs/next-auth.git",
|
"repository": "https://github.com/nextauthjs/next-auth.git",
|
||||||
@@ -27,19 +27,39 @@
|
|||||||
"nextauth"
|
"nextauth"
|
||||||
],
|
],
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.js",
|
".": {
|
||||||
"./jwt": "./jwt/index.js",
|
"types": "./index.d.ts",
|
||||||
"./react": "./react/index.js",
|
"import": "./index.js"
|
||||||
"./core": "./core/index.js",
|
},
|
||||||
"./next": "./next/index.js",
|
"./jwt": {
|
||||||
"./middleware": "./middleware.js",
|
"types": "./jwt/index.d.ts",
|
||||||
"./client/_utils": "./client/_utils.js",
|
"import": "./jwt/index.js"
|
||||||
"./providers/*": "./providers/*.js"
|
},
|
||||||
|
"./react": {
|
||||||
|
"types": "./react/index.d.ts",
|
||||||
|
"import": "./react/index.js"
|
||||||
|
},
|
||||||
|
"./next": {
|
||||||
|
"types": "./next/index.d.ts",
|
||||||
|
"import": "./next/index.js"
|
||||||
|
},
|
||||||
|
"./middleware": {
|
||||||
|
"types": "./middleware.d.ts",
|
||||||
|
"import": "./middleware.js"
|
||||||
|
},
|
||||||
|
"./client/_utils": {
|
||||||
|
"types": "./client/_utils.d.ts",
|
||||||
|
"import": "./client/_utils.js"
|
||||||
|
},
|
||||||
|
"./providers/*": {
|
||||||
|
"types": "./providers/*.d.ts",
|
||||||
|
"import": "./providers/*.js"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "pnpm clean && pnpm build:js && pnpm build:css",
|
"build": "pnpm clean && pnpm build:js && pnpm build:css",
|
||||||
"build:js": "pnpm clean && pnpm generate-providers && pnpm tsc --project tsconfig.json && babel --config-file ./config/babel.config.js src --out-dir . --extensions \".tsx,.ts,.js,.jsx\"",
|
"build:js": "pnpm clean && pnpm generate-providers && pnpm tsc --project tsconfig.json && babel --config-file ./config/babel.config.js src --out-dir . --extensions \".tsx,.ts,.js,.jsx\"",
|
||||||
"clean": "rm -rf coverage client css utils providers core jwt react next index.d.ts index.js adapters.d.ts middleware.d.ts middleware.js",
|
"clean": "rm -rf coverage client css utils providers core jwt react next lib ./*.js ./*.ts*",
|
||||||
"build:css": "postcss --config config/postcss.config.js src/**/*.css --base src --dir . && node config/wrap-css.js",
|
"build:css": "postcss --config config/postcss.config.js src/**/*.css --base src --dir . && node config/wrap-css.js",
|
||||||
"dev": "pnpm clean && pnpm generate-providers && concurrently \"pnpm watch:css\" \"pnpm watch:ts\"",
|
"dev": "pnpm clean && pnpm generate-providers && concurrently \"pnpm watch:css\" \"pnpm watch:ts\"",
|
||||||
"watch:ts": "pnpm tsc --project tsconfig.dev.json",
|
"watch:ts": "pnpm tsc --project tsconfig.dev.json",
|
||||||
|
|||||||
@@ -60,19 +60,21 @@ export interface VerificationToken {
|
|||||||
* [Create a custom adapter](https://next-auth.js.org/tutorials/creating-a-database-adapter)
|
* [Create a custom adapter](https://next-auth.js.org/tutorials/creating-a-database-adapter)
|
||||||
*/
|
*/
|
||||||
export interface Adapter {
|
export interface Adapter {
|
||||||
createUser: (user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>
|
createUser?: (user: Omit<AdapterUser, "id">) => Awaitable<AdapterUser>
|
||||||
getUser: (id: string) => Awaitable<AdapterUser | null>
|
getUser?: (id: string) => Awaitable<AdapterUser | null>
|
||||||
getUserByEmail: (email: string) => Awaitable<AdapterUser | null>
|
getUserByEmail?: (email: string) => Awaitable<AdapterUser | null>
|
||||||
/** Using the provider id and the id of the user for a specific account, get the user. */
|
/** Using the provider id and the id of the user for a specific account, get the user. */
|
||||||
getUserByAccount: (
|
getUserByAccount?: (
|
||||||
providerAccountId: Pick<AdapterAccount, "provider" | "providerAccountId">
|
providerAccountId: Pick<AdapterAccount, "provider" | "providerAccountId">
|
||||||
) => Awaitable<AdapterUser | null>
|
) => Awaitable<AdapterUser | null>
|
||||||
updateUser: (user: Partial<AdapterUser> & Pick<AdapterUser, 'id'>) => Awaitable<AdapterUser>
|
updateUser?: (
|
||||||
|
user: Partial<AdapterUser> & Pick<AdapterUser, "id">
|
||||||
|
) => Awaitable<AdapterUser>
|
||||||
/** @todo Implement */
|
/** @todo Implement */
|
||||||
deleteUser?: (
|
deleteUser?: (
|
||||||
userId: string
|
userId: string
|
||||||
) => Promise<void> | Awaitable<AdapterUser | null | undefined>
|
) => Promise<void> | Awaitable<AdapterUser | null | undefined>
|
||||||
linkAccount: (
|
linkAccount?: (
|
||||||
account: AdapterAccount
|
account: AdapterAccount
|
||||||
) => Promise<void> | Awaitable<AdapterAccount | null | undefined>
|
) => Promise<void> | Awaitable<AdapterAccount | null | undefined>
|
||||||
/** @todo Implement */
|
/** @todo Implement */
|
||||||
@@ -80,15 +82,15 @@ export interface Adapter {
|
|||||||
providerAccountId: Pick<AdapterAccount, "provider" | "providerAccountId">
|
providerAccountId: Pick<AdapterAccount, "provider" | "providerAccountId">
|
||||||
) => Promise<void> | Awaitable<AdapterAccount | undefined>
|
) => Promise<void> | Awaitable<AdapterAccount | undefined>
|
||||||
/** Creates a session for the user and returns it. */
|
/** Creates a session for the user and returns it. */
|
||||||
createSession: (session: {
|
createSession?: (session: {
|
||||||
sessionToken: string
|
sessionToken: string
|
||||||
userId: string
|
userId: string
|
||||||
expires: Date
|
expires: Date
|
||||||
}) => Awaitable<AdapterSession>
|
}) => Awaitable<AdapterSession>
|
||||||
getSessionAndUser: (
|
getSessionAndUser?: (
|
||||||
sessionToken: string
|
sessionToken: string
|
||||||
) => Awaitable<{ session: AdapterSession; user: AdapterUser } | null>
|
) => Awaitable<{ session: AdapterSession; user: AdapterUser } | null>
|
||||||
updateSession: (
|
updateSession?: (
|
||||||
session: Partial<AdapterSession> & Pick<AdapterSession, "sessionToken">
|
session: Partial<AdapterSession> & Pick<AdapterSession, "sessionToken">
|
||||||
) => Awaitable<AdapterSession | null | undefined>
|
) => Awaitable<AdapterSession | null | undefined>
|
||||||
/**
|
/**
|
||||||
@@ -96,7 +98,7 @@ export interface Adapter {
|
|||||||
* It is preferred that this method also returns the session
|
* It is preferred that this method also returns the session
|
||||||
* that is being deleted for logging purposes.
|
* that is being deleted for logging purposes.
|
||||||
*/
|
*/
|
||||||
deleteSession: (
|
deleteSession?: (
|
||||||
sessionToken: string
|
sessionToken: string
|
||||||
) => Promise<void> | Awaitable<AdapterSession | null | undefined>
|
) => Promise<void> | Awaitable<AdapterSession | null | undefined>
|
||||||
createVerificationToken?: (
|
createVerificationToken?: (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { EventCallbacks, LoggerInstance } from ".."
|
import type { EventCallbacks, InternalOptions, LoggerInstance } from ".."
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as the default `Error`, but it is JSON serializable.
|
* Same as the default `Error`, but it is JSON serializable.
|
||||||
@@ -106,7 +106,7 @@ export function eventsErrorHandler(
|
|||||||
export function adapterErrorHandler<TAdapter>(
|
export function adapterErrorHandler<TAdapter>(
|
||||||
adapter: TAdapter | undefined,
|
adapter: TAdapter | undefined,
|
||||||
logger: LoggerInstance
|
logger: LoggerInstance
|
||||||
): TAdapter | undefined {
|
): InternalOptions["adapter"] | undefined {
|
||||||
if (!adapter) return
|
if (!adapter) return
|
||||||
|
|
||||||
return Object.keys(adapter).reduce<any>((acc, name) => {
|
return Object.keys(adapter).reduce<any>((acc, name) => {
|
||||||
|
|||||||
@@ -161,9 +161,22 @@ export class SessionStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get value() {
|
/**
|
||||||
return Object.values(this.#chunks)?.join("")
|
* The JWT Session or database Session ID
|
||||||
}
|
* constructed from the cookie chunks.
|
||||||
|
*/
|
||||||
|
get value() {
|
||||||
|
// Sort the chunks by their keys before joining
|
||||||
|
const sortedKeys = Object.keys(this.#chunks).sort((a, b) => {
|
||||||
|
const aSuffix = parseInt(a.split(".").pop() || "0")
|
||||||
|
const bSuffix = parseInt(b.split(".").pop() || "0")
|
||||||
|
|
||||||
|
return aSuffix - bSuffix
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use the sorted keys to join the chunks in the correct order
|
||||||
|
return sortedKeys.map(key => this.#chunks[key]).join("")
|
||||||
|
}
|
||||||
|
|
||||||
/** Given a cookie, return a list of cookies, chunked to fit the allowed cookie size. */
|
/** Given a cookie, return a list of cookies, chunked to fit the allowed cookie size. */
|
||||||
#chunk(cookie: Cookie): Cookie[] {
|
#chunk(cookie: Cookie): Cookie[] {
|
||||||
|
|||||||
@@ -580,10 +580,12 @@ export type AuthAction =
|
|||||||
| "error"
|
| "error"
|
||||||
| "_log"
|
| "_log"
|
||||||
|
|
||||||
|
type NonNullableFields<T> = {
|
||||||
|
[P in keyof T]-?: NonNullable<T[P]>
|
||||||
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export interface InternalOptions<
|
export interface InternalOptions<TProviderType = ProviderType> {
|
||||||
TProviderType = ProviderType,
|
|
||||||
> {
|
|
||||||
providers: InternalProvider[]
|
providers: InternalProvider[]
|
||||||
/**
|
/**
|
||||||
* Parsed from `NEXTAUTH_URL` or `x-forwarded-host` and `x-forwarded-proto` if the host is trusted.
|
* Parsed from `NEXTAUTH_URL` or `x-forwarded-host` and `x-forwarded-proto` if the host is trusted.
|
||||||
@@ -602,7 +604,7 @@ export interface InternalOptions<
|
|||||||
pages: Partial<PagesOptions>
|
pages: Partial<PagesOptions>
|
||||||
jwt: JWTOptions
|
jwt: JWTOptions
|
||||||
events: Partial<EventCallbacks>
|
events: Partial<EventCallbacks>
|
||||||
adapter?: Adapter
|
adapter?: NonNullableFields<Adapter>
|
||||||
callbacks: CallbacksOptions
|
callbacks: CallbacksOptions
|
||||||
cookies: CookiesOptions
|
cookies: CookiesOptions
|
||||||
callbackUrl: string
|
callbackUrl: string
|
||||||
|
|||||||
56
packages/next-auth/src/providers/passage.ts
Normal file
56
packages/next-auth/src/providers/passage.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import type { OAuthConfig, OAuthUserConfig } from "."
|
||||||
|
|
||||||
|
/** @see [Supported Scopes](https://docs.passage.id/hosted-login/oidc-client-configuration#supported-scopes) */
|
||||||
|
export interface PassageProfile {
|
||||||
|
iss: string
|
||||||
|
/** Unique identifer in Passage for the user */
|
||||||
|
sub: string
|
||||||
|
aud: string[]
|
||||||
|
exp: number
|
||||||
|
iat: number
|
||||||
|
auth_time: number
|
||||||
|
azp: string
|
||||||
|
client_id: string
|
||||||
|
at_hash: string
|
||||||
|
c_hash: string
|
||||||
|
/** The user's email address */
|
||||||
|
email: string
|
||||||
|
/** Whether the user has verified their email address */
|
||||||
|
email_verified: boolean
|
||||||
|
/** The user's phone number */
|
||||||
|
phone: string
|
||||||
|
/** Whether the user has verified their phone number */
|
||||||
|
phone_number_verified: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Passage(
|
||||||
|
config: OAuthUserConfig<PassageProfile>
|
||||||
|
): OAuthConfig<PassageProfile> {
|
||||||
|
config.issuer = config.issuer?.replace(/\/$/, "")
|
||||||
|
return {
|
||||||
|
id: "passage",
|
||||||
|
name: "Passage",
|
||||||
|
type: "oauth",
|
||||||
|
wellKnown: `${config.issuer}/.well-known/openid-configuration`,
|
||||||
|
authorization: { params: { scope: "openid email" } },
|
||||||
|
client: { token_endpoint_auth_method: "client_secret_basic" },
|
||||||
|
checks: ["pkce", "state"],
|
||||||
|
profile(profile) {
|
||||||
|
return {
|
||||||
|
id: profile.sub,
|
||||||
|
name: null,
|
||||||
|
email: profile.email,
|
||||||
|
image: null,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style: {
|
||||||
|
logo: "/passage.svg",
|
||||||
|
logoDark: "/passage.svg",
|
||||||
|
bg: "#fff",
|
||||||
|
bgDark: "#fff",
|
||||||
|
text: "#000",
|
||||||
|
textDark: "#000",
|
||||||
|
},
|
||||||
|
options: config,
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user