-
-
Notifications
You must be signed in to change notification settings - Fork 515
/
Copy pathindex.tsx
40 lines (33 loc) · 1.22 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { useEffect } from 'react';
import { useParams } from 'react-router-dom';
import LoadingLayer from '@/components/LoadingLayer';
import useSocial from '@/containers/SocialSignInList/use-social';
import useFallbackRoute from '@/hooks/use-fallback-route';
import { useSieMethods } from '@/hooks/use-sie';
import useSingleSignOn from '@/hooks/use-single-sign-on';
const DirectSignIn = () => {
const { method, target } = useParams();
const { socialConnectors, ssoConnectors } = useSieMethods();
const { invokeSocialSignIn } = useSocial();
const invokeSso = useSingleSignOn();
const fallback = useFallbackRoute();
useEffect(() => {
if (method === 'social') {
const social = socialConnectors.find((connector) => connector.target === target);
if (social) {
void invokeSocialSignIn(social);
return;
}
}
if (method === 'sso') {
const sso = ssoConnectors.find((connector) => connector.id === target);
if (sso) {
void invokeSso(sso.id);
return;
}
}
window.location.replace('/' + fallback);
}, [fallback, invokeSocialSignIn, invokeSso, method, socialConnectors, ssoConnectors, target]);
return <LoadingLayer />;
};
export default DirectSignIn;