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

Function AuthModal

packages/shared/src/components/auth/AuthModal.tsx:23–116  ·  view source on GitHub ↗
({
  className,
  trigger,
  onRequestClose,
  ...props
}: AuthModalProps)

Source from the content-addressed store, hash-verified

21}
22
23export default function AuthModal({
24 className,
25 trigger,
26 onRequestClose,
27 ...props
28}: AuthModalProps): ReactElement {
29 const { logEvent } = useLogContext();
30 const [screenValue, setScreenValue] = useState<Display>(Display.Default);
31 const { user, closeLogin, logout, loginState } = useAuthContext();
32
33 const onClose: CloseAuthModalFunc = (e) => {
34 logEvent({
35 event_name: AuthEventNames.CloseSignUp,
36 extra: JSON.stringify({ trigger, screenValue }),
37 });
38 onRequestClose?.(e as React.MouseEvent);
39 };
40
41 const closeAndLogout: CloseAuthModalFunc = (e) => {
42 if (user && !user.username) {
43 logout(LogoutReason.IncomleteOnboarding);
44 }
45 onClose(e);
46 };
47
48 const { onContainerChange, formRef, onDiscardAttempt } = useAuthForms({
49 onDiscard: closeAndLogout,
50 });
51
52 const onSuccessfulLogin = () => {
53 loginState?.onLoginSuccess?.();
54 closeLogin();
55 };
56
57 const onSuccessfulRegistration = (
58 newUser?: LoggedUser | AnonymousUser,
59 ): void => {
60 loginState?.onRegistrationSuccess?.(newUser);
61 closeLogin();
62 };
63
64 const getDefaultDisplay = (): Display => {
65 if (loginState?.defaultDisplay) {
66 return loginState.defaultDisplay;
67 }
68 if (loginState?.formValues?.email) {
69 return Display.Registration;
70 }
71 // Always land on AuthDefault; `isLoginFlow` (tracked locally below)
72 // decides whether it renders as Sign up or Log in. We deliberately do
73 // NOT use OnboardingSignup here — that variant lives on /onboarding and
74 // the bottom AuthenticationBanner; the inline modal should reuse the
75 // same screen the rest of the app already shows for login/signup.
76 return Display.Default;
77 };
78 const defaultDisplay = getDefaultDisplay();
79
80 // `AuthOptionsInner` doesn't own `isLoginFlow` — it expects the parent to

Callers

nothing calls this directly

Calls 4

useLogContextFunction · 0.90
useAuthContextFunction · 0.90
useAuthFormsFunction · 0.85
getDefaultDisplayFunction · 0.70

Tested by

no test coverage detected