({
providers,
}: UsePrivilegedSessionProps)
| 17 | } |
| 18 | |
| 19 | const usePrivilegedSession = ({ |
| 20 | providers, |
| 21 | }: UsePrivilegedSessionProps): UsePrivilegedSession => { |
| 22 | const { openModal } = useLazyModal<LazyModal.VerifySession>(); |
| 23 | const { displayToast } = useToastNotification(); |
| 24 | const onVerification = useRef<Func>(); |
| 25 | |
| 26 | const initializePrivilegedSession = useCallback( |
| 27 | (redirect: string, onVerifiedProps?: () => void) => { |
| 28 | const url = new URL(redirect); |
| 29 | if (url.pathname.indexOf('login') === -1) { |
| 30 | return null; |
| 31 | } |
| 32 | |
| 33 | if (!url.searchParams.get('refresh')) { |
| 34 | return null; |
| 35 | } |
| 36 | |
| 37 | onVerification.current = onVerifiedProps; |
| 38 | |
| 39 | const onVerified = () => { |
| 40 | if (onVerification?.current) { |
| 41 | onVerification.current(); |
| 42 | onVerification.current = undefined; |
| 43 | } else { |
| 44 | displayToast('Session successfully verified!'); |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | return openModal({ |
| 49 | type: LazyModal.VerifySession, |
| 50 | props: { userProviders: providers, onVerified }, |
| 51 | }); |
| 52 | }, |
| 53 | [displayToast, openModal, providers], |
| 54 | ); |
| 55 | |
| 56 | return { initializePrivilegedSession }; |
| 57 | }; |
| 58 | |
| 59 | export default usePrivilegedSession; |
nothing calls this directly
no test coverage detected