MCPcopy
hub / github.com/nextauthjs/next-auth / NextAuthHandler

Function NextAuthHandler

src/core/index.ts:46–236  ·  view source on GitHub ↗
(params: NextAuthHandlerParams)

Source from the content-addressed store, hash-verified

44}
45
46export async function NextAuthHandler<
47 Body extends string | Record<string, any> | any[]
48>(params: NextAuthHandlerParams): Promise<OutgoingResponse<Body>> {
49 const { options: userOptions, req } = params
50
51 setLogger(userOptions.logger, userOptions.debug)
52
53 const assertionResult = assertConfig(params)
54
55 if (typeof assertionResult === "string") {
56 logger.warn(assertionResult)
57 } else if (assertionResult instanceof Error) {
58 // Bail out early if there's an error in the user config
59 const { pages, theme } = userOptions
60 logger.error(assertionResult.code, assertionResult)
61 if (pages?.error) {
62 return {
63 redirect: `${pages.error}?error=Configuration`,
64 }
65 }
66 const render = renderPage({ theme })
67 return render.error({ error: "configuration" })
68 }
69
70 const { action, providerId, error, method = "GET" } = req
71
72 const { options, cookies } = await init({
73 userOptions,
74 action,
75 providerId,
76 host: req.host,
77 callbackUrl: req.body?.callbackUrl ?? req.query?.callbackUrl,
78 csrfToken: req.body?.csrfToken,
79 cookies: req.cookies,
80 isPost: method === "POST",
81 })
82
83 const sessionStore = new SessionStore(
84 options.cookies.sessionToken,
85 req,
86 options.logger
87 )
88
89 if (method === "GET") {
90 const render = renderPage({ ...options, query: req.query, cookies })
91 const { pages } = options
92 switch (action) {
93 case "providers":
94 return (await routes.providers(options.providers)) as any
95 case "session": {
96 const session = await routes.session({ options, sessionStore })
97 if (session.cookies) cookies.push(...session.cookies)
98 return { ...session, cookies } as any
99 }
100 case "csrf":
101 return {
102 headers: [{ key: "Content-Type", value: "application/json" }],
103 body: { csrfToken: options.csrfToken } as any,

Callers 1

NextAuthNextHandlerFunction · 0.90

Calls 4

setLoggerFunction · 0.90
assertConfigFunction · 0.90
initFunction · 0.90
renderPageFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…