mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor: bump react sdk 0.1.15 and use callback function instead of url
This commit is contained in:
parent
c38fab89e1
commit
33f8adb2fc
6 changed files with 27 additions and 23 deletions
|
@ -19,7 +19,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@fontsource/roboto-mono": "^4.5.7",
|
"@fontsource/roboto-mono": "^4.5.7",
|
||||||
"@logto/phrases": "^0.1.0",
|
"@logto/phrases": "^0.1.0",
|
||||||
"@logto/react": "^0.1.14",
|
"@logto/react": "^0.1.15",
|
||||||
"@logto/schemas": "^0.1.0",
|
"@logto/schemas": "^0.1.0",
|
||||||
"@logto/shared": "^0.1.0",
|
"@logto/shared": "^0.1.0",
|
||||||
"@mdx-js/react": "^1.6.22",
|
"@mdx-js/react": "^1.6.22",
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
import { LogtoError, OidcError, useHandleSignInCallback } from '@logto/react';
|
import { LogtoError, OidcError, useHandleSignInCallback } from '@logto/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useHref } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import AppError from '@/components/AppError';
|
import AppError from '@/components/AppError';
|
||||||
import LogtoLoading from '@/components/LogtoLoading';
|
import LogtoLoading from '@/components/LogtoLoading';
|
||||||
|
|
||||||
const Callback = () => {
|
const Callback = () => {
|
||||||
const basename = useHref('/');
|
const navigate = useNavigate();
|
||||||
const { error } = useHandleSignInCallback(basename.slice(0, -1));
|
const { error } = useHandleSignInCallback(() => {
|
||||||
|
navigate('/');
|
||||||
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
const errorCode =
|
const errorCode =
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@logto/phrases": "^0.1.0",
|
"@logto/phrases": "^0.1.0",
|
||||||
"@logto/react": "^0.1.14",
|
"@logto/react": "^0.1.15",
|
||||||
"@logto/schemas": "^0.1.0",
|
"@logto/schemas": "^0.1.0",
|
||||||
"@logto/shared": "^0.1.0",
|
"@logto/shared": "^0.1.0",
|
||||||
"@parcel/core": "2.5.0",
|
"@parcel/core": "2.5.0",
|
||||||
|
|
|
@ -19,20 +19,20 @@ const Main = () => {
|
||||||
const isInCallback = Boolean(new URL(window.location.href).searchParams.get('code'));
|
const isInCallback = Boolean(new URL(window.location.href).searchParams.get('code'));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isAuthenticated && !isInCallback) {
|
if (isInCallback) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAuthenticated) {
|
||||||
|
(async () => {
|
||||||
|
const userInfo = await fetchUserInfo();
|
||||||
|
setUser(userInfo);
|
||||||
|
})();
|
||||||
|
} else {
|
||||||
sessionStorage.setItem(signInNotificationStorageKey, t('notification'));
|
sessionStorage.setItem(signInNotificationStorageKey, t('notification'));
|
||||||
void signIn(window.location.href);
|
void signIn(window.location.href);
|
||||||
}
|
}
|
||||||
}, [isAuthenticated, isInCallback, signIn, t]);
|
}, [fetchUserInfo, isAuthenticated, isInCallback, signIn, t]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
(async () => {
|
|
||||||
if (isAuthenticated) {
|
|
||||||
const userInfo = await fetchUserInfo();
|
|
||||||
setUser(userInfo);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}, [isAuthenticated, fetchUserInfo]);
|
|
||||||
|
|
||||||
if (isInCallback) {
|
if (isInCallback) {
|
||||||
return <Callback />;
|
return <Callback />;
|
||||||
|
|
|
@ -2,7 +2,9 @@ import { useHandleSignInCallback } from '@logto/react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const Callback = () => {
|
const Callback = () => {
|
||||||
const { error } = useHandleSignInCallback('demo-app');
|
const { error } = useHandleSignInCallback(() => {
|
||||||
|
window.location.assign('/demo-app');
|
||||||
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -621,7 +621,7 @@ importers:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@fontsource/roboto-mono': ^4.5.7
|
'@fontsource/roboto-mono': ^4.5.7
|
||||||
'@logto/phrases': ^0.1.0
|
'@logto/phrases': ^0.1.0
|
||||||
'@logto/react': ^0.1.14
|
'@logto/react': ^0.1.15
|
||||||
'@logto/schemas': ^0.1.0
|
'@logto/schemas': ^0.1.0
|
||||||
'@logto/shared': ^0.1.0
|
'@logto/shared': ^0.1.0
|
||||||
'@mdx-js/react': ^1.6.22
|
'@mdx-js/react': ^1.6.22
|
||||||
|
@ -679,7 +679,7 @@ importers:
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@fontsource/roboto-mono': 4.5.7
|
'@fontsource/roboto-mono': 4.5.7
|
||||||
'@logto/phrases': link:../phrases
|
'@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/schemas': link:../schemas
|
||||||
'@logto/shared': link:../shared
|
'@logto/shared': link:../shared
|
||||||
'@mdx-js/react': 1.6.22_react@17.0.2
|
'@mdx-js/react': 1.6.22_react@17.0.2
|
||||||
|
@ -905,7 +905,7 @@ importers:
|
||||||
packages/demo-app:
|
packages/demo-app:
|
||||||
specifiers:
|
specifiers:
|
||||||
'@logto/phrases': ^0.1.0
|
'@logto/phrases': ^0.1.0
|
||||||
'@logto/react': ^0.1.14
|
'@logto/react': ^0.1.15
|
||||||
'@logto/schemas': ^0.1.0
|
'@logto/schemas': ^0.1.0
|
||||||
'@logto/shared': ^0.1.0
|
'@logto/shared': ^0.1.0
|
||||||
'@parcel/core': 2.5.0
|
'@parcel/core': 2.5.0
|
||||||
|
@ -931,7 +931,7 @@ importers:
|
||||||
typescript: ^4.7.2
|
typescript: ^4.7.2
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@logto/phrases': link:../phrases
|
'@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/schemas': link:../schemas
|
||||||
'@logto/shared': link:../shared
|
'@logto/shared': link:../shared
|
||||||
'@parcel/core': 2.5.0
|
'@parcel/core': 2.5.0
|
||||||
|
@ -5411,8 +5411,8 @@ packages:
|
||||||
superstruct: 0.15.4
|
superstruct: 0.15.4
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/@logto/react/0.1.14_react@17.0.2:
|
/@logto/react/0.1.15_react@17.0.2:
|
||||||
resolution: {integrity: sha512-7brsrAQPUCDrKNy/G1uJ0EEw3eniwY4B8UJ4qj9WH6WVSHJj1jQj7SIC3FDIkOrBUMF6KSvDh97bRmrebLBSyQ==}
|
resolution: {integrity: sha512-GCbVRooMdCOBWJLvfDpChkKYt96Hr/Ki03xjO/gDb5KKQ3zrK9fSvN36vtUidRpddbWUsJJCK40J+FzCwUsHGg==}
|
||||||
requiresBuild: true
|
requiresBuild: true
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
react: '>=16.8.0'
|
react: '>=16.8.0'
|
||||||
|
|
Loading…
Reference in a new issue