Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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