mirror of
https://github.com/logto-io/logto.git
synced 2025-03-31 22:51:25 -05:00
feat(experience): add native listener to SSO callback page (#4930)
* feat(experience): add native listener to SSO callback page add native listenter to SSO callback page * fix(experience): add useEffect hook dependency add useEffect hook dependency
This commit is contained in:
parent
622ec4493b
commit
e82ea0a815
2 changed files with 24 additions and 6 deletions
|
@ -4,12 +4,21 @@ import { isNativeWebview } from '@/utils/native-sdk';
|
|||
|
||||
import useToast from './use-toast';
|
||||
|
||||
const useNativeMessageListener = () => {
|
||||
/**
|
||||
* UseNativeMessageListener
|
||||
*
|
||||
* Used to monitor native error message.
|
||||
* If native error message is sent, it will be displayed as toast.
|
||||
* Add a bypass parameter to bypass the native error message listener.
|
||||
*
|
||||
* @param {boolean} bypass (default: false)
|
||||
*/
|
||||
const useNativeMessageListener = (bypass = false) => {
|
||||
const { setToast } = useToast();
|
||||
|
||||
// Monitor Native Error Message
|
||||
useEffect(() => {
|
||||
if (!isNativeWebview()) {
|
||||
if (!isNativeWebview() || bypass) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -26,7 +35,7 @@ const useNativeMessageListener = () => {
|
|||
return () => {
|
||||
window.removeEventListener('message', nativeMessageHandler);
|
||||
};
|
||||
}, [setToast]);
|
||||
}, [bypass, setToast]);
|
||||
};
|
||||
|
||||
export default useNativeMessageListener;
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
import useNativeMessageListener from '@/hooks/use-native-message-listener';
|
||||
import { useSieMethods } from '@/hooks/use-sie';
|
||||
|
||||
import SignIn from '../SignIn';
|
||||
|
||||
import useSingleSignOnListener from './use-single-sign-on-listener';
|
||||
|
||||
/**
|
||||
* Single sign-on callback page
|
||||
*/
|
||||
type Props = {
|
||||
connectorId: string;
|
||||
};
|
||||
|
||||
const SingleSignOn = ({ connectorId }: Props) => {
|
||||
const { socialConnectors } = useSieMethods();
|
||||
|
||||
/* To avoid register duplicated native message listeners,
|
||||
we only add the native message listener if there are no social connectors.
|
||||
Set the bypass flag to true if there are social connectors.
|
||||
*/
|
||||
useNativeMessageListener(socialConnectors.length > 0);
|
||||
|
||||
useSingleSignOnListener(connectorId);
|
||||
|
||||
return <SignIn />;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue