@auth/nextjs
Version:
Authentication for Next.js.
26 lines (25 loc) • 740 B
JavaScript
import { Auth } from "@auth/core";
import { setEnvDefaults } from "./lib/env.js";
import { initAuth } from "./lib/index.js";
// TODO: polyfill in Next.js
if (typeof globalThis.crypto === "undefined")
globalThis.crypto = require("node:crypto").webcrypto;
/**
* Initialize Next.js Auth.
*
* @example
* ```ts title="auth.ts"
* import { NextAuth } from "@auth/nextjs"
* import GitHub from "@auth/core/providers/github"
*
* export const { handlers, auth } = NextAuth({ providers: [GitHub] })
* ```
*/
export function NextAuth(config) {
setEnvDefaults(config);
const httpHandler = (req) => Auth(req, config);
return {
handlers: { GET: httpHandler, POST: httpHandler },
auth: initAuth(config),
};
}