-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader.tsx
53 lines (48 loc) · 1.71 KB
/
header.tsx
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
import getSession from "@/lib/session";
import Link from "next/link";
import db from "@/lib/db";
import { notFound, redirect } from "next/navigation";
import { collection, getDocs, query, where } from "firebase/firestore";
import { firestore } from "@/config/firebase/firebase";
import { COLLECTION_NAME_PROFILE } from "@/lib/constants";
import Avatar from "./avatar";
import { headers } from "next/headers";
import { IProfileReponse } from "@/model/reponses";
import HeaderAvatar from "./header-avatar";
const logOut = async () => {
"use server";
const session = await getSession();
session.destroy();
redirect("/log-in");
};
export async function Header() {
const id = (await getSession()).id;
const host = headers().get("host");
const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
const result = await fetch(`${protocol}://${host}/api/user/${id}`);
const json: IProfileReponse = await result.json();
if (json.status === 400) {
redirect("/create-profile");
}
return (
<header className="px-6 py-2 flex items-center justify-between w-screen z-10 bg-white fixed">
<Link href={"/"} className="text-base font-bold text-pink-500">
PRAISEBOX
</Link>
<div className="flex gap-4 items-center flex-nowrap">
<form action={logOut}>
<button className="px-4 py-2 bg-pink-100 text-pink-400 rounded-full font-medium text-sm">
Sign out
</button>
</form>
<Link href={"/profile"}>
<HeaderAvatar
bodyType={json.profile.avatar.bodyType}
eyeType={json.profile.avatar.eyeType}
eyeColor={json.profile.avatar.eyeColor}
/>
</Link>
</div>
</header>
);
}