mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 06:24:06 +01:00
fix: profile not reload on password signin
This commit is contained in:
parent
0929364496
commit
b752008e86
@ -1,6 +1,5 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@ -11,29 +10,16 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
|
||||||
import { Bell, Heart, Wallet } from "lucide-react";
|
import { Bell, Heart, Wallet } from "lucide-react";
|
||||||
import { LogoutButton } from "@/components/auth/logoutButton";
|
import { LogoutButton } from "@/components/auth/logoutButton";
|
||||||
import useSession from "@/lib/supabase/useSession";
|
|
||||||
import { useUserRole } from "@/hooks/useUserRole";
|
import { useUserRole } from "@/hooks/useUserRole";
|
||||||
|
|
||||||
const UnAuthenticatedComponents = () => {
|
interface AuthenticatedComponentsProps {
|
||||||
return (
|
uid: string;
|
||||||
<div className="flex gap-2 pl-2">
|
}
|
||||||
<Link href="/auth">
|
|
||||||
<Button variant="secondary" className="border-2 border-border">
|
|
||||||
Login
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
<Link href="/auth/signup">
|
|
||||||
<Button>Sign up</Button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const AuthenticatedComponents = ({ uid }: { uid: string }) => {
|
export const AuthenticatedComponents = ({ uid }: AuthenticatedComponentsProps) => {
|
||||||
let notifications = 100;
|
const notifications = 100;
|
||||||
const displayValue = notifications >= 100 ? "..." : notifications;
|
const displayValue = notifications >= 100 ? "..." : notifications;
|
||||||
const { data } = useUserRole();
|
const { data } = useUserRole();
|
||||||
|
|
||||||
@ -68,7 +54,7 @@ const AuthenticatedComponents = ({ uid }: { uid: string }) => {
|
|||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuItem>Settings</DropdownMenuItem>
|
<DropdownMenuItem>Settings</DropdownMenuItem>
|
||||||
<DropdownMenuItem>Support</DropdownMenuItem>
|
<DropdownMenuItem>Support</DropdownMenuItem>
|
||||||
{data != null && data != undefined && data.role === "admin" && (
|
{data?.role === "admin" && (
|
||||||
<DropdownMenuItem>
|
<DropdownMenuItem>
|
||||||
<Link href="/admin">Admin</Link>
|
<Link href="/admin">Admin</Link>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
@ -82,31 +68,3 @@ const AuthenticatedComponents = ({ uid }: { uid: string }) => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ProfileBar() {
|
|
||||||
const { session } = useSession();
|
|
||||||
const user = session?.user;
|
|
||||||
const [sessionLoaded, setSessionLoaded] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!session) {
|
|
||||||
setSessionLoaded(true);
|
|
||||||
}
|
|
||||||
}, [session]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{sessionLoaded ? (
|
|
||||||
user ? (
|
|
||||||
<AuthenticatedComponents uid={user.id} />
|
|
||||||
) : (
|
|
||||||
<UnAuthenticatedComponents />
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<div>
|
|
||||||
<Skeleton className="rounded-lg h-full w-[160px]" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
19
src/components/navigationBar/UnAuthenticatedComponents.tsx
Normal file
19
src/components/navigationBar/UnAuthenticatedComponents.tsx
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
|
export const UnAuthenticatedComponents = () => {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2 pl-2">
|
||||||
|
<Link href="/auth">
|
||||||
|
<Button variant="secondary" className="border-2 border-border">
|
||||||
|
Login
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
<Link href="/auth/signup">
|
||||||
|
<Button>Sign up</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@ -14,7 +14,10 @@ import {
|
|||||||
NavigationMenuTrigger,
|
NavigationMenuTrigger,
|
||||||
} from "@/components/ui/navigation-menu";
|
} from "@/components/ui/navigation-menu";
|
||||||
import { SearchBar } from "./serchBar";
|
import { SearchBar } from "./serchBar";
|
||||||
import { ProfileBar } from "./profileBar";
|
import { AuthenticatedComponents } from "./AuthenticatedComponents";
|
||||||
|
import { UnAuthenticatedComponents } from "./UnAuthenticatedComponents";
|
||||||
|
|
||||||
|
import { getUserId } from "@/lib/supabase/actions/getUserId";
|
||||||
|
|
||||||
const ListItem = React.forwardRef<React.ElementRef<"a">, React.ComponentPropsWithoutRef<"a">>(
|
const ListItem = React.forwardRef<React.ElementRef<"a">, React.ComponentPropsWithoutRef<"a">>(
|
||||||
({ className, title, children, ...props }, ref) => {
|
({ className, title, children, ...props }, ref) => {
|
||||||
@ -40,7 +43,9 @@ const ListItem = React.forwardRef<React.ElementRef<"a">, React.ComponentPropsWit
|
|||||||
);
|
);
|
||||||
ListItem.displayName = "ListItem";
|
ListItem.displayName = "ListItem";
|
||||||
|
|
||||||
export function NavigationBar() {
|
export async function NavigationBar() {
|
||||||
|
const userId = await getUserId();
|
||||||
|
|
||||||
const businessComponents = [
|
const businessComponents = [
|
||||||
{
|
{
|
||||||
title: "Business",
|
title: "Business",
|
||||||
@ -112,7 +117,7 @@ export function NavigationBar() {
|
|||||||
<div className="flex gap-2 pl-2">
|
<div className="flex gap-2 pl-2">
|
||||||
<ThemeToggle />
|
<ThemeToggle />
|
||||||
<Separator orientation="vertical" className="mx-3" />
|
<Separator orientation="vertical" className="mx-3" />
|
||||||
<ProfileBar />
|
{userId ? <AuthenticatedComponents uid={userId} /> : <UnAuthenticatedComponents />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
12
src/lib/supabase/actions/getUserId.ts
Normal file
12
src/lib/supabase/actions/getUserId.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
|
||||||
|
|
||||||
|
export async function getUserId() {
|
||||||
|
const supabase = createSupabaseClient();
|
||||||
|
const { data, error } = await supabase.auth.getUser();
|
||||||
|
|
||||||
|
if (error || !data?.user) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.user.id;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user