diff --git a/packages/console/package.json b/packages/console/package.json index 8a9c1c432..d52f83320 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -19,7 +19,7 @@ "devDependencies": { "@fontsource/roboto-mono": "^4.5.7", "@logto/phrases": "^0.1.0", - "@logto/react": "^0.1.14", + "@logto/react": "^0.1.15", "@logto/schemas": "^0.1.0", "@logto/shared": "^0.1.0", "@mdx-js/react": "^1.6.22", diff --git a/packages/console/src/pages/Callback/index.tsx b/packages/console/src/pages/Callback/index.tsx index 09b789b50..187cb2cc1 100644 --- a/packages/console/src/pages/Callback/index.tsx +++ b/packages/console/src/pages/Callback/index.tsx @@ -1,13 +1,15 @@ import { LogtoError, OidcError, useHandleSignInCallback } from '@logto/react'; import React from 'react'; -import { useHref } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; import AppError from '@/components/AppError'; import LogtoLoading from '@/components/LogtoLoading'; const Callback = () => { - const basename = useHref('/'); - const { error } = useHandleSignInCallback(basename.slice(0, -1)); + const navigate = useNavigate(); + const { error } = useHandleSignInCallback(() => { + navigate('/'); + }); if (error) { const errorCode = diff --git a/packages/demo-app/package.json b/packages/demo-app/package.json index e887c1390..e14c59363 100644 --- a/packages/demo-app/package.json +++ b/packages/demo-app/package.json @@ -18,7 +18,7 @@ }, "devDependencies": { "@logto/phrases": "^0.1.0", - "@logto/react": "^0.1.14", + "@logto/react": "^0.1.15", "@logto/schemas": "^0.1.0", "@logto/shared": "^0.1.0", "@parcel/core": "2.5.0", diff --git a/packages/demo-app/src/App.tsx b/packages/demo-app/src/App.tsx index 1d32cb03f..869ff915c 100644 --- a/packages/demo-app/src/App.tsx +++ b/packages/demo-app/src/App.tsx @@ -19,20 +19,20 @@ const Main = () => { const isInCallback = Boolean(new URL(window.location.href).searchParams.get('code')); useEffect(() => { - if (!isAuthenticated && !isInCallback) { + if (isInCallback) { + return; + } + + if (isAuthenticated) { + (async () => { + const userInfo = await fetchUserInfo(); + setUser(userInfo); + })(); + } else { sessionStorage.setItem(signInNotificationStorageKey, t('notification')); void signIn(window.location.href); } - }, [isAuthenticated, isInCallback, signIn, t]); - - useEffect(() => { - (async () => { - if (isAuthenticated) { - const userInfo = await fetchUserInfo(); - setUser(userInfo); - } - })(); - }, [isAuthenticated, fetchUserInfo]); + }, [fetchUserInfo, isAuthenticated, isInCallback, signIn, t]); if (isInCallback) { return ; diff --git a/packages/demo-app/src/Callback.tsx b/packages/demo-app/src/Callback.tsx index c76ca3598..939d6186c 100644 --- a/packages/demo-app/src/Callback.tsx +++ b/packages/demo-app/src/Callback.tsx @@ -2,7 +2,9 @@ import { useHandleSignInCallback } from '@logto/react'; import React from 'react'; const Callback = () => { - const { error } = useHandleSignInCallback('demo-app'); + const { error } = useHandleSignInCallback(() => { + window.location.assign('/demo-app'); + }); if (error) { return ( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4ac35c8ea..1dae51eaf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -621,7 +621,7 @@ importers: specifiers: '@fontsource/roboto-mono': ^4.5.7 '@logto/phrases': ^0.1.0 - '@logto/react': ^0.1.14 + '@logto/react': ^0.1.15 '@logto/schemas': ^0.1.0 '@logto/shared': ^0.1.0 '@mdx-js/react': ^1.6.22 @@ -679,7 +679,7 @@ importers: devDependencies: '@fontsource/roboto-mono': 4.5.7 '@logto/phrases': link:../phrases - '@logto/react': 0.1.14_react@17.0.2 + '@logto/react': 0.1.15_react@17.0.2 '@logto/schemas': link:../schemas '@logto/shared': link:../shared '@mdx-js/react': 1.6.22_react@17.0.2 @@ -905,7 +905,7 @@ importers: packages/demo-app: specifiers: '@logto/phrases': ^0.1.0 - '@logto/react': ^0.1.14 + '@logto/react': ^0.1.15 '@logto/schemas': ^0.1.0 '@logto/shared': ^0.1.0 '@parcel/core': 2.5.0 @@ -931,7 +931,7 @@ importers: typescript: ^4.7.2 devDependencies: '@logto/phrases': link:../phrases - '@logto/react': 0.1.14_react@17.0.2 + '@logto/react': 0.1.15_react@17.0.2 '@logto/schemas': link:../schemas '@logto/shared': link:../shared '@parcel/core': 2.5.0 @@ -5411,8 +5411,8 @@ packages: superstruct: 0.15.4 dev: true - /@logto/react/0.1.14_react@17.0.2: - resolution: {integrity: sha512-7brsrAQPUCDrKNy/G1uJ0EEw3eniwY4B8UJ4qj9WH6WVSHJj1jQj7SIC3FDIkOrBUMF6KSvDh97bRmrebLBSyQ==} + /@logto/react/0.1.15_react@17.0.2: + resolution: {integrity: sha512-GCbVRooMdCOBWJLvfDpChkKYt96Hr/Ki03xjO/gDb5KKQ3zrK9fSvN36vtUidRpddbWUsJJCK40J+FzCwUsHGg==} requiresBuild: true peerDependencies: react: '>=16.8.0'