mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(console): better error handling when linking social in profile page (#3335)
This commit is contained in:
parent
c69df70358
commit
d2327d6298
1 changed files with 27 additions and 4 deletions
|
@ -4,10 +4,18 @@ import { useLocation } from 'react-router-dom';
|
|||
import AppLoading from '@/components/AppLoading';
|
||||
import { adminTenantEndpoint, meApi, profileSocialLinkingKeyPrefix } from '@/consts';
|
||||
import { useStaticApi } from '@/hooks/use-api';
|
||||
import { useConfirmModal } from '@/hooks/use-confirm-modal';
|
||||
|
||||
import { handleError } from '../../utils';
|
||||
|
||||
const HandleSocialCallback = () => {
|
||||
const { search } = useLocation();
|
||||
const api = useStaticApi({ prefixUrl: adminTenantEndpoint, resourceIndicator: meApi.indicator });
|
||||
const { show: showModal } = useConfirmModal();
|
||||
const api = useStaticApi({
|
||||
prefixUrl: adminTenantEndpoint,
|
||||
resourceIndicator: meApi.indicator,
|
||||
hideErrorToast: true,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
|
@ -22,12 +30,27 @@ const HandleSocialCallback = () => {
|
|||
);
|
||||
const connectorData = Object.fromEntries(queries);
|
||||
|
||||
try {
|
||||
await api.post('me/social/link-identity', { json: { connectorId, connectorData } });
|
||||
|
||||
window.close();
|
||||
} catch (error: unknown) {
|
||||
void handleError(error, async (code, message) => {
|
||||
if (code === 'user.identity_already_in_use') {
|
||||
await showModal({
|
||||
ModalContent: message,
|
||||
type: 'alert',
|
||||
cancelButtonText: 'general.got_it',
|
||||
});
|
||||
window.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
}, [api, search]);
|
||||
}, [api, search, showModal]);
|
||||
|
||||
return <AppLoading />;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue