From 62824a6b83adc6664f9a8ae6be37c99ce0469ab6 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 25 May 2023 13:56:53 +0100 Subject: [PATCH] Added logout button --- src/app/components/Navbar.tsx | 128 ++++++++++++++++++ src/app/components/ProfileDropDown.tsx | 62 +++++++++ .../components/signin/GoogleSignInButton.jsx | 3 - src/app/home/page.tsx | 10 +- 4 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 src/app/components/Navbar.tsx create mode 100644 src/app/components/ProfileDropDown.tsx diff --git a/src/app/components/Navbar.tsx b/src/app/components/Navbar.tsx new file mode 100644 index 00000000..fa459e90 --- /dev/null +++ b/src/app/components/Navbar.tsx @@ -0,0 +1,128 @@ +"use client"; + +import React, { useState } from "react"; +import { Transition } from "@headlessui/react"; +import ProfileDropDown from "./ProfileDropDown"; + +function makeLink(href: string, label: string) { + return ( + + {label} + + ); +} + +function Nav({ pageName }: { pageName: string }) { + const [isOpen, setIsOpen] = useState(false); + return ( +
+ + +
+
+

{pageName}

+
+
+
+ ); +} + +export default Nav; diff --git a/src/app/components/ProfileDropDown.tsx b/src/app/components/ProfileDropDown.tsx new file mode 100644 index 00000000..6c5a20ed --- /dev/null +++ b/src/app/components/ProfileDropDown.tsx @@ -0,0 +1,62 @@ +"use client"; + +import { Menu } from "@headlessui/react"; +import { signOut, useSession } from "next-auth/react"; +import Link from "next/link"; +import { redirect } from "next/navigation"; + +function ProfileDropDown() { + const { data: session, status } = useSession({ + required: true, + onUnauthenticated() { + redirect("/?callbackUrl=/home"); + }, + }); + + if (status !== "authenticated" || !session || !session.user) { + return null; + } + + return ( + + + {session.user.image ? ( + {session.user.image} + ) : ( + + + + + + )} + + + + + Help + + + + + + + + + + ); +} + +export default ProfileDropDown; diff --git a/src/app/components/signin/GoogleSignInButton.jsx b/src/app/components/signin/GoogleSignInButton.jsx index e61abefc..6dad75b2 100644 --- a/src/app/components/signin/GoogleSignInButton.jsx +++ b/src/app/components/signin/GoogleSignInButton.jsx @@ -9,9 +9,6 @@ const GoogleSignInButton = () => { const searchParams = useSearchParams(); const callbackUrl = searchParams.get("callbackUrl"); - console.log("WYF"); - console.log(callbackUrl); - return (