From 0e18e86e05db6fe0fd73a9fae009889886d2d32f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Sat, 5 Dec 2020 19:27:34 +0100 Subject: [PATCH 1/2] docs: remove Promise.resolve() where not needed --- www/docs/configuration/callbacks.md | 24 +++++++++---------- www/docs/configuration/options.md | 8 +++---- www/docs/configuration/providers.md | 4 ++-- www/docs/providers/credentials.md | 8 +++---- www/docs/providers/google.md | 4 ++-- .../tutorials/creating-a-database-adapter.md | 4 ++-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/www/docs/configuration/callbacks.md b/www/docs/configuration/callbacks.md index 958c58bb76..2ecc4745e1 100644 --- a/www/docs/configuration/callbacks.md +++ b/www/docs/configuration/callbacks.md @@ -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 } ... } @@ -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 } } } @@ -97,8 +97,8 @@ callbacks: { */ redirect: async (url, baseUrl) => { return url.startsWith(baseUrl) - ? Promise.resolve(url) - : Promise.resolve(baseUrl) + ? url + : baseUrl } } ``` @@ -127,7 +127,7 @@ callbacks: { */ session: async (session, user) => { session.foo = 'bar' // Add property to session - return Promise.resolve(session) + return session } } ``` @@ -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 } } ``` diff --git a/www/docs/configuration/options.md b/www/docs/configuration/options.md index e5877c941b..8c7ecbc648 100644 --- a/www/docs/configuration/options.md +++ b/www/docs/configuration/options.md @@ -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 } } ``` diff --git a/www/docs/configuration/providers.md b/www/docs/configuration/providers.md index 1459c80c1c..b88945c427 100644 --- a/www/docs/configuration/providers.md +++ b/www/docs/configuration/providers.md @@ -203,9 +203,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 } } }) diff --git a/www/docs/providers/credentials.md b/www/docs/providers/credentials.md index ea3c5dc65d..37d8a1d89c 100644 --- a/www/docs/providers/credentials.md +++ b/www/docs/providers/credentials.md @@ -51,10 +51,10 @@ 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 @@ -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" }, @@ -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" }, diff --git a/www/docs/providers/google.md b/www/docs/providers/google.md index 77eab2606b..ad091cfb96 100644 --- a/www/docs/providers/google.md +++ b/www/docs/providers/google.md @@ -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 } }, } diff --git a/www/docs/tutorials/creating-a-database-adapter.md b/www/docs/tutorials/creating-a-database-adapter.md index a7fabc8dd5..c3b3eb74e3 100644 --- a/www/docs/tutorials/creating-a-database-adapter.md +++ b/www/docs/tutorials/creating-a-database-adapter.md @@ -149,7 +149,7 @@ const Adapter = (config, options = {}) => { return null } - return Promise.resolve({ + return { createUser, getUser, getUserByEmail, @@ -166,7 +166,7 @@ const Adapter = (config, options = {}) => { createVerificationRequest, getVerificationRequest, deleteVerificationRequest - }) + } } return { From ac1a19722a80ab038af3934d22f9904de44f51de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Sat, 5 Dec 2020 19:27:55 +0100 Subject: [PATCH 2/2] docs: remove Promise.reject() where not needed --- www/docs/providers/credentials.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/www/docs/providers/credentials.md b/www/docs/providers/credentials.md index 37d8a1d89c..4daf2ee762 100644 --- a/www/docs/providers/credentials.md +++ b/www/docs/providers/credentials.md @@ -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` @@ -56,8 +56,8 @@ providers: [ // If you return null or false then the credentials will be rejected 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 } } })