mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
* refactor: decouple Next.js from core (WIP) * refactor: use `base` instead of `baseUrl`+`basePath` * fix: signout route * refactor(ts): convert files to TS * fix: imports * refactor: convert callback route * fix: add `next` files to package * chore(dev): alias npm email * refactor: do not merge req with user options * refactor: rename userOptions to options * refactor: use native `URL` in `parseUrl` * refactor: move Next.js specific code to `next` module * refactor(ts): return `OutgoingResponse` on all routes * fix: change `base` to `url` * feat: introduce `getServerSession` * refactor: move main logic to `handler` file * chore(dev): showcase `getServerSession` * feat: extract `sessionToken` from Authorization header * fix: pass headers to getServerSession * refactor: rename `server` to `core` * refactor: re-export `next-auth/next` in `next-auth` * fix: add `core` to npm package * fix: re-export default method * feat: return `body`+`header` instead of `json`,`text` * feat: pass `NEXTAUTH_URL` as a variable to core * refactor: simplify Next.js wrapper * feat: export `client/_utils` * fix(ts): suppress TS errors
91 lines
2.0 KiB
TypeScript
91 lines
2.0 KiB
TypeScript
import type { NextApiRequest, NextApiResponse } from "next"
|
|
|
|
import type {
|
|
CallbacksOptions,
|
|
CookiesOptions,
|
|
EventCallbacks,
|
|
LoggerInstance,
|
|
PagesOptions,
|
|
SessionOptions,
|
|
Theme,
|
|
Awaitable,
|
|
} from ".."
|
|
|
|
import type {
|
|
OAuthConfig,
|
|
EmailConfig,
|
|
CredentialsConfig,
|
|
ProviderType,
|
|
} from "../providers"
|
|
import type { JWTOptions } from "../jwt"
|
|
import type { Adapter } from "../adapters"
|
|
import { InternalUrl } from "./parse-url"
|
|
|
|
// Below are types that are only supposed be used by next-auth internally
|
|
|
|
/** @internal */
|
|
export type InternalProvider<T extends ProviderType = any> = (T extends "oauth"
|
|
? OAuthConfig<any>
|
|
: T extends "email"
|
|
? EmailConfig
|
|
: T extends "credentials"
|
|
? CredentialsConfig
|
|
: never) & {
|
|
signinUrl: string
|
|
callbackUrl: string
|
|
}
|
|
|
|
export type NextAuthAction =
|
|
| "providers"
|
|
| "session"
|
|
| "csrf"
|
|
| "signin"
|
|
| "signout"
|
|
| "callback"
|
|
| "verify-request"
|
|
| "error"
|
|
| "_log"
|
|
|
|
/** @internal */
|
|
export interface InternalOptions<T extends ProviderType = any> {
|
|
providers: InternalProvider[]
|
|
/**
|
|
* Parsed from `NEXTAUTH_URL` or `VERCEL_URL`.
|
|
* @default "http://localhost:3000/api/auth"
|
|
*/
|
|
url: InternalUrl
|
|
action: NextAuthAction
|
|
provider: T extends string
|
|
? InternalProvider<T>
|
|
: InternalProvider<T> | undefined
|
|
csrfToken?: string
|
|
csrfTokenVerified?: boolean
|
|
secret: string
|
|
theme: Theme
|
|
debug: boolean
|
|
logger: LoggerInstance
|
|
session: Required<SessionOptions>
|
|
pages: Partial<PagesOptions>
|
|
jwt: JWTOptions
|
|
events: Partial<EventCallbacks>
|
|
adapter?: Adapter
|
|
callbacks: CallbacksOptions
|
|
cookies: CookiesOptions
|
|
callbackUrl: string
|
|
}
|
|
|
|
/** @internal */
|
|
export interface NextAuthRequest extends NextApiRequest {
|
|
options: InternalOptions
|
|
}
|
|
|
|
/** @internal */
|
|
export type NextAuthResponse<T = any> = NextApiResponse<T>
|
|
|
|
/** @internal */
|
|
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
export type NextAuthApiHandler<Result = void, Response = any> = (
|
|
req: NextAuthRequest,
|
|
res: NextAuthResponse<Response>
|
|
) => Awaitable<Result>
|