Files
tweakcn/components/auth-dialog-wrapper.tsx
T
Luis Llanes d661f7d6d7 refactor: Routable components follow Next.js file conventions (#110)
* feat: add AuthDialogWrapper to main layout to work in every route

* refactor: move footer to global components

* refactor: separate route components into layouts, pages, and loading components

* chore: remove AuthDialogWrapper from AI page after it was moved to root layout
2025-06-04 23:38:56 +05:30

37 lines
1.2 KiB
TypeScript

"use client";
import { AuthDialog } from "@/app/(auth)/components/auth-dialog";
import { useAuthStore } from "@/store/auth-store";
import { useEffect } from "react";
import { authClient } from "@/lib/auth-client";
import { executePostLoginAction } from "@/hooks/use-post-login-action";
import { usePostHog } from "posthog-js/react";
export function AuthDialogWrapper() {
const { isOpen, mode, closeAuthDialog, postLoginAction, clearPostLoginAction } = useAuthStore();
const { data: session } = authClient.useSession();
const posthog = usePostHog();
useEffect(() => {
if (isOpen && session) {
closeAuthDialog();
}
if (session && session.user && session.user.email) {
// Identify user with PostHog
posthog.identify(session.user.email, {
name: session.user.name,
email: session.user.email,
});
}
if (session && postLoginAction) {
// Execute action immediately - the system will now handle waiting for handlers
executePostLoginAction(postLoginAction);
clearPostLoginAction();
}
}, [session, isOpen, closeAuthDialog, postLoginAction, clearPostLoginAction, posthog]);
return <AuthDialog open={isOpen} onOpenChange={closeAuthDialog} initialMode={mode} />;
}