Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Remove unnecessary promises #915

Merged
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
24 changes: 12 additions & 12 deletions www/docs/configuration/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ You can specify a handler for any of the callbacks below.
...
callbacks: {
signIn: async (user, account, profile) => {
return Promise.resolve(true)
return true
},
redirect: async (url, baseUrl) => {
return Promise.resolve(baseUrl)
return baseUrl
},
session: async (session, user) => {
return Promise.resolve(session)
return session
},
jwt: async (token, user, account, profile, isNewUser) => {
return Promise.resolve(token)
return token
}
...
}
Expand All @@ -50,13 +50,13 @@ callbacks: {
signIn: async (user, account, profile) => {
const isAllowedToSignIn = true
if (isAllowedToSignIn) {
return Promise.resolve(true)
return true
} else {
// Return false to display a default error message
return Promise.resolve(false)
return false
// You can also Reject this callback with an Error or with a URL:
// return Promise.reject(new Error('error message')) // Redirect to error page
// return Promise.reject('/path/to/redirect') // Redirect to a URL
// throw new Error('error message') // Redirect to error page
// return '/path/to/redirect' // Redirect to a URL
}
}
}
Expand Down Expand Up @@ -97,8 +97,8 @@ callbacks: {
*/
redirect: async (url, baseUrl) => {
return url.startsWith(baseUrl)
? Promise.resolve(url)
: Promise.resolve(baseUrl)
? url
: baseUrl
}
}
```
Expand Down Expand Up @@ -127,7 +127,7 @@ callbacks: {
*/
session: async (session, user) => {
session.foo = 'bar' // Add property to session
return Promise.resolve(session)
return session
}
}
```
Expand Down Expand Up @@ -171,7 +171,7 @@ callbacks: {
const isSignIn = (user) ? true : false
// Add auth_time to token on signin in
if (isSignIn) { token.auth_time = Math.floor(Date.now() / 1000) }
return Promise.resolve(token)
return token
}
}
```
Expand Down
8 changes: 4 additions & 4 deletions www/docs/configuration/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,16 @@ You can specify a handler for any of the callbacks below.
```js
callbacks: {
signIn: async (user, account, profile) => {
return Promise.resolve(true)
return true
},
redirect: async (url, baseUrl) => {
return Promise.resolve(baseUrl)
return baseUrl
},
session: async (session, user) => {
return Promise.resolve(session)
return session
},
jwt: async (token, user, account, profile, isNewUser) => {
return Promise.resolve(token)
return token
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions www/docs/configuration/providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ providers: [
}
if (user) {
// Any user object returned here will be saved in the JSON Web Token
return Promise.resolve(user)
return user
} else {
return Promise.resolve(null)
return null
}
}
})
Expand Down
16 changes: 8 additions & 8 deletions www/docs/providers/credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ The Credentials provider is specified like other providers, except that you need

If you return `false` or `null` then an error will be displayed advising the user to check their details.

3. `Promise.Rejected()` with an Error or a URL.
3. You can throw an Error or a URL (a string).

If you reject the promise with an Error, the user will be sent to the error page with the error message as a query parameter. If you reject the promise with a URL (a string), the user will be redirected to the URL.
If you throw an Error, the user will be sent to the error page with the error message as a query parameter. If throw a URL (a string), the user will be redirected to the URL.

```js title="pages/api/auth/[...nextauth].js"
import Providers from `next-auth/providers`
Expand All @@ -51,13 +51,13 @@ providers: [

if (user) {
// Any object returned will be saved in `user` property of the JWT
return Promise.resolve(user)
return user
} else {
// If you return null or false then the credentials will be rejected
return Promise.resolve(null)
return null
// You can also Reject this callback with an Error or with a URL:
// return Promise.reject(new Error('error message')) // Redirect to error page
// return Promise.reject('/path/to/redirect') // Redirect to a URL
// throw new Error('error message') // Redirect to error page
// throw '/path/to/redirect' // Redirect to a URL
}
}
})
Expand All @@ -84,7 +84,7 @@ As with all providers, the order you specify them is the order they are displaye
name: "Domain Account",
authorize: async (credentials) => {
const user = { /* add function to get user */ }
return Promise.resolve(user)
return user
},
credentials: {
domain: { label: "Domain", type: "text ", placeholder: "CORPNET", value: "CORPNET" },
Expand All @@ -97,7 +97,7 @@ As with all providers, the order you specify them is the order they are displaye
name: "Two Factor Auth",
authorize: async (credentials) => {
const user = { /* add function to get user */ }
return Promise.resolve(user)
return user
},
credentials: {
email: { label: "Username", type: "text ", placeholder: "jsmith" },
Expand Down
4 changes: 2 additions & 2 deletions www/docs/providers/google.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ const options = {
if (account.provider === 'google' &&
profile.verified_email === true &&
profile.email.endsWith('@example.com')) {
return Promise.resolve(true)
return true
} else {
return Promise.resolve(false)
return false
}
},
}
Expand Down
4 changes: 2 additions & 2 deletions www/docs/tutorials/creating-a-database-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const Adapter = (config, options = {}) => {
return null
}

return Promise.resolve({
return {
createUser,
getUser,
getUserByEmail,
Expand All @@ -166,7 +166,7 @@ const Adapter = (config, options = {}) => {
createVerificationRequest,
getVerificationRequest,
deleteVerificationRequest
})
}
}

return {
Expand Down