Skip to content

Commit

Permalink
Revert "feat: simplify NextAuth instantiation" (#910)
Browse files Browse the repository at this point in the history
This reverts commit b86ffa5.
  • Loading branch information
balazsorban44 committed Dec 5, 2020
1 parent b86ffa5 commit 341fae2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -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({
Expand All @@ -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
Expand Down
10 changes: 1 addition & 9 deletions src/server/index.js
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
6 changes: 4 additions & 2 deletions www/docs/getting-started/example.md
Expand Up @@ -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({
Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions www/docs/schemas/adapters.md
Expand Up @@ -74,15 +74,17 @@ import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient()

export default NextAuth({
const options = {
providers: [
Providers.Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET
})
],
adapter: Adapters.Prisma.Adapter({ prisma }),
})
}

export default (req, res) => NextAuth(req, res, options)
```

:::tip
Expand Down
6 changes: 4 additions & 2 deletions www/docs/tutorials/ldap-auth.md
Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions www/docs/tutorials/typeorm-custom-models.md
Expand Up @@ -62,7 +62,7 @@ import Adapters from "next-auth/adapters"

import Models from "../../../models"

export default NextAuth({
const options = {
providers: [
// Your providers
],
Expand All @@ -77,7 +77,9 @@ export default NextAuth({
},
}
),
})
}

export default (req, res) => NextAuth(req, res, options)
```


6 changes: 4 additions & 2 deletions www/src/pages/index.js
Expand Up @@ -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({
Expand All @@ -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

1 comment on commit 341fae2

@vercel
Copy link

@vercel vercel bot commented on 341fae2 Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.