MCPcopy Create free account
hub / github.com/dailydotdev/apps / usePrivilegedSession

Function usePrivilegedSession

packages/shared/src/hooks/usePrivilegedSession.ts:19–57  ·  view source on GitHub ↗
({
  providers,
}: UsePrivilegedSessionProps)

Source from the content-addressed store, hash-verified

17}
18
19const 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
59export default usePrivilegedSession;

Callers

nothing calls this directly

Calls 3

useLazyModalFunction · 0.90
useToastNotificationFunction · 0.90
openModalFunction · 0.85

Tested by

no test coverage detected