0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(experience): fix silent error bug (#5031)

gix silent error bug
This commit is contained in:
simeng-li 2023-12-01 14:43:40 +08:00 committed by GitHub
parent 9fd49c6caa
commit 61d1894fa9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 7 deletions

View file

@ -115,7 +115,7 @@ const App = () => {
{/* Single sign on */}
{isDevelopmentFeaturesEnabled && (
<Route path={singleSignOnPath}>
<Route path={singleSignOnPath} element={<LoadingLayerProvider />}>
<Route path="email" element={<SingleSignOnEmail />} />
<Route path="connectors" element={<SingleSignOnConnectors />} />
</Route>

View file

@ -36,10 +36,11 @@ const useCheckSingleSignOn = () => {
/**
* Check if the email is registered with any SSO connectors
* @param {string} email
* @param {boolean} continueSignIn - whether to continue the single sign-on flow if the email is registered with any SSO connectors
* @returns {Promise<boolean>} - true if the email is registered with any SSO connectors
*/
const onSubmit = useCallback(
async (email: string) => {
async (email: string, continueSignIn = false) => {
clearContext();
const [error, result] = await request(email);
@ -62,6 +63,10 @@ const useCheckSingleSignOn = () => {
setSsoConnectors(connectors);
setEmail(email);
if (!continueSignIn) {
return true;
}
// If there is only one connector, we can directly invoke the SSO flow
if (connectors.length === 1 && connectors[0]?.id) {
await singleSignOn(connectors[0].id);

View file

@ -3,6 +3,7 @@ import { useState, useMemo, useCallback } from 'react';
import type { PasswordSignInPayload } from '@/apis/interaction';
import { signInWithPasswordIdentifier } from '@/apis/interaction';
import useApi from '@/hooks/use-api';
import useCheckSingleSignOn from '@/hooks/use-check-single-sign-on';
import type { ErrorHandlers } from '@/hooks/use-error-handler';
import useErrorHandler from '@/hooks/use-error-handler';
@ -10,6 +11,7 @@ import usePreSignInErrorHandler from './use-pre-sign-in-error-handler';
const usePasswordSignIn = () => {
const [errorMessage, setErrorMessage] = useState<string>();
const { onSubmit: checkSingleSignOn } = useCheckSingleSignOn();
const clearErrorMessage = useCallback(() => {
setErrorMessage('');
@ -24,9 +26,6 @@ const usePasswordSignIn = () => {
'session.invalid_credentials': (error) => {
setErrorMessage(error.message);
},
'session.sso_enabled': (_error) => {
// Hide the toast and do nothing
},
...preSignInErrorHandler,
}),
[preSignInErrorHandler]
@ -34,6 +33,15 @@ const usePasswordSignIn = () => {
const onSubmit = useCallback(
async (payload: PasswordSignInPayload) => {
// Check if the email is registered with any SSO connectors. If the email is registered with any SSO connectors, we should not proceed to the next step
if (payload.email) {
const result = await checkSingleSignOn(payload.email);
if (result) {
return;
}
}
const [error, result] = await asyncSignIn(payload);
if (error) {
@ -46,7 +54,7 @@ const usePasswordSignIn = () => {
window.location.replace(result.redirectTo);
}
},
[asyncSignIn, errorHandlers, handleError]
[asyncSignIn, checkSingleSignOn, errorHandlers, handleError]
);
return {

View file

@ -40,7 +40,7 @@ const SingleSignOnEmail = () => {
const onSubmitHandler = useCallback(
async (event?: React.FormEvent<HTMLFormElement>) => {
clearErrorMessage();
await handleSubmit(async ({ identifier: { value } }) => onSubmit(value))(event);
await handleSubmit(async ({ identifier: { value } }) => onSubmit(value, true))(event);
},
[clearErrorMessage, handleSubmit, onSubmit]
);