Skip to content

Commit

Permalink
fix: Use consistent error type between doc, logger and error class (#…
Browse files Browse the repository at this point in the history
…5046)

* Keep error from being logged twice

The same errors have been logged, firstly before throwing
OAuthCallbackError, later in the catch-clause of it.

This commit removes the former and lets the latter survive,
because logging functionality seems better to reside in the
same neighborhood.

* doc: Merge CALLBACK_OAUTH_ERROR to OAUTH_CALLBACK_ERROR

* doc: This particular error from openid-client comes with SIGNIN_OAUTH_ERROR

* Provide logger with `providerId`

Co-authored-by: Thang Vu <thvu@hey.com>

Co-authored-by: Thang Vu <thvu@hey.com>
  • Loading branch information
sato11 and ThangHuuVu committed Aug 22, 2022
1 parent 448ec10 commit 3131971
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
11 changes: 5 additions & 6 deletions docs/docs/errors.md
Expand Up @@ -76,7 +76,11 @@ Please check your OAuth provider and make sure your URLs and other options are

If you are using an OAuth v1 provider, check your OAuth v1 provider settings, especially the OAuth token and OAuth token secret.

#### CALLBACK_OAUTH_ERROR
3. `openid-client` version mismatch

If you are seeing `expected 200 OK with body but no body was returned`, it might have happened due to `openid-client` (which is peer dependency) node version mismatch. For instance, `openid-client` requires `>=14.2.0` for `lts/fermium` and has similar limits for the other versions. For the full list of the compatible node versions please see [package.json](https://github.com/panva/node-openid-client/blob/2a84e46992e1ebeaf685c3f87b65663d126e81aa/package.json#L78).

#### OAUTH_CALLBACK_ERROR

This can occur during the handling of the callback if the `code_verifier` cookie was not found or an invalid state was returned from the OAuth provider.

Expand Down Expand Up @@ -179,8 +183,3 @@ Useful links:
- https://next-auth.js.org/configuration/pages
- https://nextjs.org/docs/advanced-features/middleware#matcher

### Other

#### oauth_callback_error expected 200 OK with body but no body was returned

This error might happen with some of the providers. It happens due to `openid-client`(which is peer dependency) node version mismatch. For instance, `openid-client` requires `>=14.2.0` for `lts/fermium` and has similar limits for the other versions. For the full list of the compatible node versions please see [package.json](https://github.com/panva/node-openid-client/blob/2a84e46992e1ebeaf685c3f87b65663d126e81aa/package.json#L78)
4 changes: 0 additions & 4 deletions packages/next-auth/src/core/lib/oauth/callback.ts
Expand Up @@ -153,10 +153,6 @@ export default async function oAuthCallback(params: {
})
return { ...profileResult, cookies: resCookies }
} catch (error) {
logger.error("OAUTH_CALLBACK_ERROR", {
error: error as Error,
providerId: provider.id,
})
throw new OAuthCallbackError(error as Error)
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/next-auth/src/core/routes/callback.ts
Expand Up @@ -190,7 +190,10 @@ export default async function callback(params: {
}
} catch (error) {
if ((error as Error).name === "OAuthCallbackError") {
logger.error("CALLBACK_OAUTH_ERROR", error as Error)
logger.error("OAUTH_CALLBACK_ERROR", {
error: error as Error,
providerId: provider.id,
})
return { redirect: `${url}/error?error=OAuthCallback`, cookies }
}
logger.error("OAUTH_CALLBACK_ERROR", error as Error)
Expand Down

1 comment on commit 3131971

@vercel
Copy link

@vercel vercel bot commented on 3131971 Aug 22, 2022

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.