Skip to content

Commit 341fae2

Browse files
Revert "feat: simplify NextAuth instantiation" (#910)
This reverts commit b86ffa5.
1 parent b86ffa5 commit 341fae2

File tree

7 files changed

+25
-21
lines changed

7 files changed

+25
-21
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Alternatively you can raise a PR directly with your fixes on [**DefinitelyTyped*
6868
import NextAuth from 'next-auth'
6969
import Providers from 'next-auth/providers'
7070

71-
export default NextAuth({
71+
const options = {
7272
providers: [
7373
// OAuth authentication providers
7474
Providers.Apple({
@@ -87,7 +87,9 @@ export default NextAuth({
8787
],
8888
// SQL or MongoDB database (or leave empty)
8989
database: process.env.DATABASE_URL
90-
})
90+
}
91+
92+
export default (req, res) => NextAuth(req, res, options)
9193
```
9294

9395
### Add React Component

src/server/index.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (!process.env.NEXTAUTH_URL) {
2121
logger.warn('NEXTAUTH_URL', 'NEXTAUTH_URL environment variable not set')
2222
}
2323

24-
async function NextAuth (req, res, userSuppliedOptions) {
24+
export default async (req, res, userSuppliedOptions) => {
2525
// To the best of my knowledge, we need to return a promise here
2626
// to avoid early termination of calls to the serverless function
2727
// (and then return that promise when we are done) - eslint
@@ -313,11 +313,3 @@ async function NextAuth (req, res, userSuppliedOptions) {
313313
}
314314
})
315315
}
316-
317-
export default async (...args) => {
318-
if (args.length === 1) {
319-
return (req, res) => NextAuth(req, res, args[0])
320-
}
321-
322-
return NextAuth(...args)
323-
}

www/docs/getting-started/example.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To add NextAuth.js to a project create a file called `[...nextauth].js` in `page
2121
import NextAuth from 'next-auth'
2222
import Providers from 'next-auth/providers'
2323

24-
export default NextAuth({
24+
const options = {
2525
// Configure one or more authentication providers
2626
providers: [
2727
Providers.GitHub({
@@ -33,7 +33,9 @@ export default NextAuth({
3333

3434
// A database is optional, but required to persist accounts in a database
3535
database: process.env.DATABASE_URL,
36-
})
36+
}
37+
38+
export default (req, res) => NextAuth(req, res, options)
3739
```
3840

3941
All requests to `/api/auth/*` (signin, callback, signout, etc) will automatically be handed by NextAuth.js.

www/docs/schemas/adapters.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,17 @@ import { PrismaClient } from '@prisma/client'
7474

7575
const prisma = new PrismaClient()
7676

77-
export default NextAuth({
77+
const options = {
7878
providers: [
7979
Providers.Google({
8080
clientId: process.env.GOOGLE_CLIENT_ID,
8181
clientSecret: process.env.GOOGLE_CLIENT_SECRET
8282
})
8383
],
8484
adapter: Adapters.Prisma.Adapter({ prisma }),
85-
})
85+
}
86+
87+
export default (req, res) => NextAuth(req, res, options)
8688
```
8789

8890
:::tip

www/docs/tutorials/ldap-auth.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const ldap = require("ldapjs");
1414
import NextAuth from "next-auth";
1515
import Providers from "next-auth/providers";
1616

17-
export default NextAuth({
17+
const options = {
1818
providers: [
1919
Providers.Credentials({
2020
name: "LDAP",
@@ -64,7 +64,9 @@ export default NextAuth({
6464
secret: process.env.NEXTAUTH_SECRET,
6565
encryption: true, // Very important to encrypt the JWT, otherwise you're leaking username+password into the browser
6666
},
67-
});
67+
};
68+
69+
export default (req, res) => NextAuth(req, res, options);
6870
```
6971

7072
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.

www/docs/tutorials/typeorm-custom-models.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import Adapters from "next-auth/adapters"
6262

6363
import Models from "../../../models"
6464

65-
export default NextAuth({
65+
const options = {
6666
providers: [
6767
// Your providers
6868
],
@@ -77,7 +77,9 @@ export default NextAuth({
7777
},
7878
}
7979
),
80-
})
80+
}
81+
82+
export default (req, res) => NextAuth(req, res, options)
8183
```
8284

8385

www/src/pages/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ const serverlessFunctionCode = `
219219
import NextAuth from 'next-auth'
220220
import Providers from 'next-auth/providers'
221221
222-
export default NextAuth({
222+
const options = {
223223
providers: [
224224
// OAuth authentication providers...
225225
Providers.Apple({
@@ -242,7 +242,9 @@ export default NextAuth({
242242
],
243243
// Optional SQL or MongoDB database to persist users
244244
database: process.env.DATABASE_URL
245-
})
245+
}
246+
247+
export default (req, res) => NextAuth(req, res, options)
246248
`.trim()
247249

248250
export default Home

0 commit comments

Comments
 (0)