From 91d24123001e507d3cc7bb26940810cae69ba229 Mon Sep 17 00:00:00 2001 From: simeng-li Date: Thu, 28 Sep 2023 10:25:32 +0800 Subject: [PATCH] fix(console): fix the invalid_target error block console consent issue (#4592) fix(console): fix the invalid_target error block AC consent issue fix the invalid_target error block AC consent issue --- packages/console/package.json | 2 +- .../src/containers/ErrorBoundary/index.tsx | 20 +++++++++- pnpm-lock.yaml | 39 ++++++++++++++++++- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/packages/console/package.json b/packages/console/package.json index 069342acb..4c0d21084 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -32,7 +32,7 @@ "@logto/language-kit": "workspace:^1.0.0", "@logto/phrases": "workspace:^1.5.0", "@logto/phrases-experience": "workspace:^1.3.1", - "@logto/react": "^2.1.0", + "@logto/react": "^2.1.2", "@logto/schemas": "workspace:^1.9.1", "@logto/shared": "workspace:^2.0.1", "@mdx-js/react": "^1.6.22", diff --git a/packages/console/src/containers/ErrorBoundary/index.tsx b/packages/console/src/containers/ErrorBoundary/index.tsx index 94719453b..8eaedf76e 100644 --- a/packages/console/src/containers/ErrorBoundary/index.tsx +++ b/packages/console/src/containers/ErrorBoundary/index.tsx @@ -1,4 +1,4 @@ -import { LogtoClientError, LogtoError, OidcError } from '@logto/react'; +import { LogtoClientError, LogtoError, OidcError, LogtoRequestError } from '@logto/react'; import { conditional } from '@silverhand/essentials'; import { ResponseError } from '@withtyped/client'; import { type TFunction } from 'i18next'; @@ -11,6 +11,23 @@ import AppError from '@/components/AppError'; import SessionExpired from '@/components/SessionExpired'; import { isInCallback } from '@/utils/url'; +/** + * Returns true if the error is an OIDC invalid_grant error. + * + * OIDC request error is globally converted to the LogtoRequestError. + * @see {@link @logto/core/packages/core/src/middleware/koa-oidc-error-handler.ts} + * We need to check the error code to determine if it is an OIDC invalid_grant error. + */ +const isOidcInvalidGrantError = (error: Error) => { + if (!(error instanceof LogtoRequestError)) { + return false; + } + + const oidcGrantErrors = ['oidc.invalid_grant', 'oidc.invalid_target']; + + return oidcGrantErrors.includes(error.code); +}; + type Props = { children: ReactNode; t: TFunction<'translation', 'admin_console'>; @@ -70,6 +87,7 @@ class ErrorBoundary extends Component { if ( error instanceof LogtoError || error instanceof LogtoClientError || + isOidcInvalidGrantError(error) || (error instanceof HTTPError && error.response.status === 401) || (error instanceof ResponseError && error.status === 401) ) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1cd3a2e97..9cd069bca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2852,8 +2852,8 @@ importers: specifier: workspace:^1.3.1 version: link:../phrases-experience '@logto/react': - specifier: ^2.1.0 - version: 2.1.0(react@18.2.0) + specifier: ^2.1.2 + version: 2.1.2(react@18.2.0) '@logto/schemas': specifier: workspace:^1.9.1 version: link:../schemas @@ -7289,6 +7289,14 @@ packages: js-base64: 3.7.5 dev: true + /@logto/browser@2.1.2: + resolution: {integrity: sha512-LADZHT7LTyiWDwWmBwh3qAtOg+IVEjfaFKBTB/RQBc5T9xYO4q4JcyW1XgpMlkc0uLqOtW3uOGztUVs0ugi6/g==} + dependencies: + '@logto/client': 2.2.3 + '@silverhand/essentials': 2.8.4 + js-base64: 3.7.5 + dev: true + /@logto/client@2.1.0: resolution: {integrity: sha512-vw8xDW8k38/58Q1r592z/9JdsmUh4+LMmoVm/Nu7LbWKlT32eD3H9hZDkFK9XEHpriifhI0hP7asGWEmhrEUuQ==} dependencies: @@ -7307,6 +7315,15 @@ packages: jose: 4.14.4 dev: true + /@logto/client@2.2.3: + resolution: {integrity: sha512-xq4LhQ6ItbukAHgsMDcgfspTpdpO5sSfSEugpOrGP/nLwzGTfBO78OSUfMdBQEDr5+3SRmONuSjUBBwssOLINA==} + dependencies: + '@logto/js': 2.1.3 + '@silverhand/essentials': 2.8.4 + camelcase-keys: 7.0.2 + jose: 4.14.4 + dev: true + /@logto/cloud@0.2.5-444ed49(zod@3.20.2): resolution: {integrity: sha512-UirssRQV8+UAG/d0amK3qSrZstYW8+VUtfRWcKN8Ka0oJbPaNQL+fW+8OCB39ikQqT39KLrClXbThu3akPUWhw==} engines: {node: ^18.12.0} @@ -7345,6 +7362,14 @@ packages: jose: 4.14.2 dev: true + /@logto/js@2.1.3: + resolution: {integrity: sha512-TOuoC5gHx/SfY5gcGSBfw63x5TpM6Lm/9J5y0Jy003Z1DZARUlpz0KbzyCVAIC/+6qIefkmNPHKl1rq9MB/hog==} + dependencies: + '@silverhand/essentials': 2.8.4 + camelcase-keys: 7.0.2 + jose: 4.14.4 + dev: true + /@logto/node@2.1.1: resolution: {integrity: sha512-joSzzAqaRKeEquRenoFrIXXkNxkJci5zSkk4afywz1P8tTcTysnV4eXaBmwXNpmDfQdtHBwRdSACZPLgeF8JiQ==} dependencies: @@ -7366,6 +7391,16 @@ packages: react: 18.2.0 dev: true + /@logto/react@2.1.2(react@18.2.0): + resolution: {integrity: sha512-4Fz5GG5N7y9ynYVutuLZgBornkVccaxG1vmAOxt233wfFPmNzESJ+TlYGe2FbngC7z9xfT6c7f9Q+1LZQmrzVg==} + peerDependencies: + react: '>=16.8.0 || ^18.0.0' + dependencies: + '@logto/browser': 2.1.2 + '@silverhand/essentials': 2.8.4 + react: 18.2.0 + dev: true + /@manypkg/find-root@1.1.0: resolution: {integrity: sha512-mki5uBvhHzO8kYYix/WRy2WX8S3B5wdVSc9D6KcU5lQNglP2yt58/VfLuAK49glRXChosY8ap2oJ1qgma3GUVA==} dependencies: