0
Fork 0
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:
Charles Zhao 2022-06-09 15:19:44 +08:00
parent c38fab89e1
commit 33f8adb2fc
No known key found for this signature in database
GPG key ID: 4858774754C92DF2
6 changed files with 27 additions and 23 deletions

View file

@ -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",

View file

@ -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 =

View file

@ -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",

View file

@ -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 <Callback />;

View file

@ -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 (

View file

@ -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'