feat: add custom navbar with inline supabase clients and custom dropdown
All checks were successful
Staging Build / build (push) Successful in 2m22s
All checks were successful
Staging Build / build (push) Successful in 2m22s
This commit is contained in:
49
shop/components/Navbar.tsx
Normal file
49
shop/components/Navbar.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { createServerClient } from "@supabase/ssr";
|
||||
import { cookies } from "next/headers";
|
||||
import { NavbarClient } from "@/components/NavbarClient";
|
||||
|
||||
export async function Navbar() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
const supabaseUrl = process.env.SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL;
|
||||
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY || process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY || process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY;
|
||||
|
||||
if (!supabaseUrl || !supabaseAnonKey) {
|
||||
// Falls keine Env-Vars da sind, leeren User an Client übergeben
|
||||
return <NavbarClient user={null} />;
|
||||
}
|
||||
|
||||
const supabase = createServerClient(
|
||||
supabaseUrl,
|
||||
supabaseAnonKey,
|
||||
{
|
||||
cookies: {
|
||||
getAll() {
|
||||
return cookieStore.getAll();
|
||||
},
|
||||
setAll(cookiesToSet) {
|
||||
try {
|
||||
cookiesToSet.forEach(({ name, value, options }) =>
|
||||
cookieStore.set(name, value, options),
|
||||
);
|
||||
} catch {
|
||||
// Kann in Server Components ignoriert werden, da dort keine Cookies gesetzt werden können
|
||||
}
|
||||
},
|
||||
},
|
||||
cookieOptions: {
|
||||
name: "webshop-auth-token",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
let user = null;
|
||||
try {
|
||||
const { data } = await supabase.auth.getUser();
|
||||
user = data.user;
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen des Users in Navbar:", error);
|
||||
}
|
||||
|
||||
return <NavbarClient user={user} />;
|
||||
}
|
||||
Reference in New Issue
Block a user