diff --git a/README.md b/README.md index 8f883f3348..5cad3a447e 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Alternatively you can raise a PR directly with your fixes on [**DefinitelyTyped* import NextAuth from 'next-auth' import Providers from 'next-auth/providers' -export default NextAuth({ +const options = { providers: [ // OAuth authentication providers Providers.Apple({ @@ -87,7 +87,9 @@ export default NextAuth({ ], // SQL or MongoDB database (or leave empty) database: process.env.DATABASE_URL -}) +} + +export default (req, res) => NextAuth(req, res, options) ``` ### Add React Component diff --git a/src/server/index.js b/src/server/index.js index 2b47a2e635..8c8cbb29b5 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -21,7 +21,7 @@ if (!process.env.NEXTAUTH_URL) { logger.warn('NEXTAUTH_URL', 'NEXTAUTH_URL environment variable not set') } -async function NextAuth (req, res, userSuppliedOptions) { +export default async (req, res, userSuppliedOptions) => { // To the best of my knowledge, we need to return a promise here // to avoid early termination of calls to the serverless function // (and then return that promise when we are done) - eslint @@ -313,11 +313,3 @@ async function NextAuth (req, res, userSuppliedOptions) { } }) } - -export default async (...args) => { - if (args.length === 1) { - return (req, res) => NextAuth(req, res, args[0]) - } - - return NextAuth(...args) -} diff --git a/www/docs/getting-started/example.md b/www/docs/getting-started/example.md index 8b7eb32516..e223800856 100644 --- a/www/docs/getting-started/example.md +++ b/www/docs/getting-started/example.md @@ -21,7 +21,7 @@ To add NextAuth.js to a project create a file called `[...nextauth].js` in `page import NextAuth from 'next-auth' import Providers from 'next-auth/providers' -export default NextAuth({ +const options = { // Configure one or more authentication providers providers: [ Providers.GitHub({ @@ -33,7 +33,9 @@ export default NextAuth({ // A database is optional, but required to persist accounts in a database database: process.env.DATABASE_URL, -}) +} + +export default (req, res) => NextAuth(req, res, options) ``` All requests to `/api/auth/*` (signin, callback, signout, etc) will automatically be handed by NextAuth.js. diff --git a/www/docs/schemas/adapters.md b/www/docs/schemas/adapters.md index f08bb14e6b..8547de14db 100644 --- a/www/docs/schemas/adapters.md +++ b/www/docs/schemas/adapters.md @@ -74,7 +74,7 @@ import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient() -export default NextAuth({ +const options = { providers: [ Providers.Google({ clientId: process.env.GOOGLE_CLIENT_ID, @@ -82,7 +82,9 @@ export default NextAuth({ }) ], adapter: Adapters.Prisma.Adapter({ prisma }), -}) +} + +export default (req, res) => NextAuth(req, res, options) ``` :::tip diff --git a/www/docs/tutorials/ldap-auth.md b/www/docs/tutorials/ldap-auth.md index 12a273e772..a5c19b9a49 100644 --- a/www/docs/tutorials/ldap-auth.md +++ b/www/docs/tutorials/ldap-auth.md @@ -14,7 +14,7 @@ const ldap = require("ldapjs"); import NextAuth from "next-auth"; import Providers from "next-auth/providers"; -export default NextAuth({ +const options = { providers: [ Providers.Credentials({ name: "LDAP", @@ -64,7 +64,9 @@ export default NextAuth({ secret: process.env.NEXTAUTH_SECRET, encryption: true, // Very important to encrypt the JWT, otherwise you're leaking username+password into the browser }, -}); +}; + +export default (req, res) => NextAuth(req, res, options); ``` The idea is that once one is authenticated with the LDAP server, one can pass through both the username/DN and password to the JWT stored in the browser. diff --git a/www/docs/tutorials/typeorm-custom-models.md b/www/docs/tutorials/typeorm-custom-models.md index 1fc9f1e218..dcfa8e46c5 100644 --- a/www/docs/tutorials/typeorm-custom-models.md +++ b/www/docs/tutorials/typeorm-custom-models.md @@ -62,7 +62,7 @@ import Adapters from "next-auth/adapters" import Models from "../../../models" -export default NextAuth({ +const options = { providers: [ // Your providers ], @@ -77,7 +77,9 @@ export default NextAuth({ }, } ), -}) +} + +export default (req, res) => NextAuth(req, res, options) ``` diff --git a/www/src/pages/index.js b/www/src/pages/index.js index 5ef1f9f64d..565df70f2f 100644 --- a/www/src/pages/index.js +++ b/www/src/pages/index.js @@ -219,7 +219,7 @@ const serverlessFunctionCode = ` import NextAuth from 'next-auth' import Providers from 'next-auth/providers' -export default NextAuth({ +const options = { providers: [ // OAuth authentication providers... Providers.Apple({ @@ -242,7 +242,9 @@ export default NextAuth({ ], // Optional SQL or MongoDB database to persist users database: process.env.DATABASE_URL -}) +} + +export default (req, res) => NextAuth(req, res, options) `.trim() export default Home