diff --git a/app/components/auth/ProfileDialog.tsx b/app/components/auth/ProfileDialog.tsx
new file mode 100644
index 0000000..694c112
--- /dev/null
+++ b/app/components/auth/ProfileDialog.tsx
@@ -0,0 +1,38 @@
+import { Dialog, DialogTitle, DialogDescription, DialogRoot } from '~/components/ui/Dialog';
+import { useAuth } from '~/hooks/useAuth';
+
+interface ProfileDialogProps {
+ isOpen: boolean;
+ onClose: () => void;
+}
+
+export function ProfileDialog({ isOpen, onClose }: ProfileDialogProps) {
+ const { user } = useAuth();
+
+ if (!user) return null;
+
+ return (
+
+
+
+ );
+}
diff --git a/app/components/auth/SubscriptionDialog.tsx b/app/components/auth/SubscriptionDialog.tsx
new file mode 100644
index 0000000..d1cb1ce
--- /dev/null
+++ b/app/components/auth/SubscriptionDialog.tsx
@@ -0,0 +1,24 @@
+import { Dialog, DialogTitle, DialogDescription, DialogRoot } from '~/components/ui/Dialog';
+
+interface SubscriptionDialogProps {
+ isOpen: boolean;
+ onClose: () => void;
+}
+
+export function SubscriptionDialog({ isOpen, onClose }: SubscriptionDialogProps) {
+ return (
+
+
+
+ );
+}
diff --git a/app/components/header/UserMenu.tsx b/app/components/header/UserMenu.tsx
index 4c5e84a..9e8cf74 100644
--- a/app/components/header/UserMenu.tsx
+++ b/app/components/header/UserMenu.tsx
@@ -1,74 +1,82 @@
import { Menu, Transition } from '@headlessui/react';
-import { Fragment } from 'react';
+import { Fragment, useState } from 'react';
import { useAuth } from '~/hooks/useAuth';
import { Avatar } from '~/components/ui/Avatar';
-import { Link } from '@remix-run/react';
+import { ProfileDialog } from '~/components/auth/ProfileDialog';
+import { SubscriptionDialog } from '~/components/auth/SubscriptionDialog';
export function UserMenu() {
const { user, logout } = useAuth();
+ const [isProfileOpen, setIsProfileOpen] = useState(false);
+ const [isSubscriptionOpen, setIsSubscriptionOpen] = useState(false);
if (!user) return null;
return (
-
+
+ setIsProfileOpen(false)} />
+ setIsSubscriptionOpen(false)} />
+ >
);
}
diff --git a/app/hooks/useAuth.ts b/app/hooks/useAuth.ts
index 26ed9d1..6544ff6 100644
--- a/app/hooks/useAuth.ts
+++ b/app/hooks/useAuth.ts
@@ -15,13 +15,25 @@ export function useAuth() {
const navigate = useNavigate();
useEffect(() => {
- const token = localStorage.getItem('token');
- const storedUser = localStorage.getItem('user');
- if (token && storedUser) {
- setIsAuthenticated(true);
- setUser(JSON.parse(storedUser));
- }
- setIsLoading(false);
+ const checkAuth = () => {
+ const token = localStorage.getItem('token');
+ const storedUser = localStorage.getItem('user');
+ if (token && storedUser) {
+ setIsAuthenticated(true);
+ setUser(JSON.parse(storedUser));
+ } else {
+ setIsAuthenticated(false);
+ setUser(null);
+ }
+ setIsLoading(false);
+ };
+
+ checkAuth();
+ window.addEventListener('storage', checkAuth);
+
+ return () => {
+ window.removeEventListener('storage', checkAuth);
+ };
}, []);
const login = (token: string, userData: User) => {
@@ -36,6 +48,7 @@ export function useAuth() {
localStorage.removeItem('user');
setIsAuthenticated(false);
setUser(null);
+ navigate('/');
};
return { isAuthenticated, isLoading, user, login, logout };