-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDesktopUserMenu.tsx
More file actions
80 lines (72 loc) · 1.82 KB
/
Copy pathDesktopUserMenu.tsx
File metadata and controls
80 lines (72 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"use client";
import { createClient } from "@/utils/supabase/client";
import { useEffect, useState } from "react";
import { signInWithGoogle, signOut } from "@/lib/auth-actions";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { User } from "lucide-react";
import { redirect } from "next/navigation";
import { Button } from "../ui/button";
type UserRole = "buyer" | "seller";
export default function DesktopUserMenu({ userRole }: { userRole: UserRole }) {
const [loggedIn, setLoggedIn] = useState(true);
useEffect(() => {
const checkLoginStatus = async () => {
const supabase = await createClient();
const { data, error } = await supabase.auth.getUser();
if (error || !data.user) {
setLoggedIn(false);
} else {
setLoggedIn(true);
}
};
checkLoginStatus();
}, []);
const navigateToSettings = () => {
redirect("/account");
};
const handleLogin = () => {
signInWithGoogle();
};
const handleLogout = () => {
signOut();
};
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
aria-label="Account"
className="rounded-full">
<User className="h-5 w-5" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{loggedIn ? (
<>
<DropdownMenuItem
onClick={navigateToSettings}
className="text-base">
Settings
</DropdownMenuItem>
<DropdownMenuItem
onClick={handleLogout}
className="text-base text-red-600">
Log Out
</DropdownMenuItem>
</>
) : (
<DropdownMenuItem onClick={handleLogin} className="text-base">
<User className="mr-2 h-4 w-4" />
<span>Log In</span>
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
);
}