From 4f909b02f013f4fded35d175ae2813e84ce92030 Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 5 Jan 2024 16:05:34 +0000 Subject: [PATCH] feat: logout --- src/app/auth/login/page.tsx | 2 +- src/app/boards/[...id]/page.tsx | 2 +- src/app/boards/layout.tsx | 2 +- src/app/boards/page.tsx | 2 +- src/app/cards/[...id]/page.tsx | 2 +- src/app/cards/layout.tsx | 2 +- src/app/components/UserMenu.tsx | 69 +++++++++++++++++++ src/app/{_components => components}/auth.tsx | 11 +-- .../{_components => components}/dashboard.tsx | 35 +++------- src/app/{_components => components}/modal.tsx | 0 10 files changed, 90 insertions(+), 37 deletions(-) create mode 100644 src/app/components/UserMenu.tsx rename src/app/{_components => components}/auth.tsx (61%) rename src/app/{_components => components}/dashboard.tsx (58%) rename src/app/{_components => components}/modal.tsx (100%) diff --git a/src/app/auth/login/page.tsx b/src/app/auth/login/page.tsx index e1eeb0fe..1c473dda 100644 --- a/src/app/auth/login/page.tsx +++ b/src/app/auth/login/page.tsx @@ -1,4 +1,4 @@ -import { Login } from "~/app/_components/auth"; +import { Login } from "~/app/components/auth"; export default function LoginPage() { return ( diff --git a/src/app/boards/[...id]/page.tsx b/src/app/boards/[...id]/page.tsx index aa3b3caa..d5f644c7 100644 --- a/src/app/boards/[...id]/page.tsx +++ b/src/app/boards/[...id]/page.tsx @@ -16,7 +16,7 @@ import { api } from "~/trpc/react"; import { useBoard } from "~/app/providers/board"; import { useModal } from "~/app/providers/modal"; -import Modal from "~/app/_components/modal"; +import Modal from "~/app/components/modal"; import BoardDropdown from "./components/BoardDropdown"; import { DeleteBoardConfirmation } from "./components/DeleteBoardConfirmation"; diff --git a/src/app/boards/layout.tsx b/src/app/boards/layout.tsx index a49b1cf0..12318549 100644 --- a/src/app/boards/layout.tsx +++ b/src/app/boards/layout.tsx @@ -1,4 +1,4 @@ -import Dashboard from "~/app/_components/dashboard"; +import Dashboard from "~/app/components/dashboard"; export default function Layout(props: { children: React.ReactNode }) { return {props.children}; diff --git a/src/app/boards/page.tsx b/src/app/boards/page.tsx index 9f77aead..100769c4 100644 --- a/src/app/boards/page.tsx +++ b/src/app/boards/page.tsx @@ -4,7 +4,7 @@ import { HiOutlinePlusSmall } from "react-icons/hi2"; import { BoardsList } from "./components/BoardsList"; import { useModal } from "~/app/providers/modal"; -import Modal from "~/app/_components/modal"; +import Modal from "~/app/components/modal"; import { NewBoardForm } from "~/app/boards/components/NewBoardForm"; diff --git a/src/app/cards/[...id]/page.tsx b/src/app/cards/[...id]/page.tsx index 3b17a2f1..04ab58ca 100644 --- a/src/app/cards/[...id]/page.tsx +++ b/src/app/cards/[...id]/page.tsx @@ -12,7 +12,7 @@ import LabelSelector from "./components/LabelSelector"; import ListSelector from "./components/ListSelector"; import { NewLabelForm } from "./components/NewLabelForm"; -import Modal from "~/app/_components/modal"; +import Modal from "~/app/components/modal"; import { useModal } from "~/app/providers/modal"; import { api } from "~/trpc/react"; diff --git a/src/app/cards/layout.tsx b/src/app/cards/layout.tsx index a49b1cf0..12318549 100644 --- a/src/app/cards/layout.tsx +++ b/src/app/cards/layout.tsx @@ -1,4 +1,4 @@ -import Dashboard from "~/app/_components/dashboard"; +import Dashboard from "~/app/components/dashboard"; export default function Layout(props: { children: React.ReactNode }) { return {props.children}; diff --git a/src/app/components/UserMenu.tsx b/src/app/components/UserMenu.tsx new file mode 100644 index 00000000..6334803b --- /dev/null +++ b/src/app/components/UserMenu.tsx @@ -0,0 +1,69 @@ +"use client"; + +import { Fragment } from "react"; +import Image from "next/image"; +import { signOut } from "next-auth/react"; +import { Menu, Transition } from "@headlessui/react"; +import { HiOutlineLogout } from "react-icons/hi"; + +interface UserMenuProps { + imageUrl: string | undefined; + email: string; +} + +export default function UserMenu({ imageUrl, email }: UserMenuProps) { + return ( + +
+ + {imageUrl ? ( + + ) : ( + + + + + + )} + {email} + +
+ + + +
+ + {() => ( + + )} + +
+
+
+
+ ); +} diff --git a/src/app/_components/auth.tsx b/src/app/components/auth.tsx similarity index 61% rename from src/app/_components/auth.tsx rename to src/app/components/auth.tsx index bfd91273..9c94a39f 100644 --- a/src/app/_components/auth.tsx +++ b/src/app/components/auth.tsx @@ -14,14 +14,17 @@ export function Login() { email: "", }} onSubmit={async (values: FormValues) => { - await signIn("email", { email: values.email }); + await signIn("email", { + email: values.email, + callbackUrl: "/boards", + }); }} >
@@ -33,7 +36,7 @@ export function Login() { placeholder="you@example.com" autoComplete="email" required - className="bg-dark-500 focus:ring-dark-900 ring-dark-900 text-dark-1000 block w-full rounded-md border-0 bg-white/5 py-1.5 shadow-sm ring-1 ring-inset focus:ring-2 focus:ring-inset sm:text-sm sm:leading-6" + className="block w-full rounded-md border-0 bg-dark-500 bg-white/5 py-1.5 text-dark-1000 shadow-sm ring-1 ring-inset ring-dark-900 focus:ring-2 focus:ring-inset focus:ring-dark-900 sm:text-sm sm:leading-6" />
@@ -41,7 +44,7 @@ export function Login() {
diff --git a/src/app/_components/dashboard.tsx b/src/app/components/dashboard.tsx similarity index 58% rename from src/app/_components/dashboard.tsx rename to src/app/components/dashboard.tsx index dac8b068..599d241a 100644 --- a/src/app/_components/dashboard.tsx +++ b/src/app/components/dashboard.tsx @@ -1,4 +1,3 @@ -import Image from "next/image"; import { redirect } from "next/navigation"; import { auth } from "~/server/auth"; @@ -6,6 +5,7 @@ import { auth } from "~/server/auth"; import boardsIcon from "~/app/assets/boards.json"; import ReactiveButton from "~/app/components/ReactiveButton"; +import UserMenu from "~/app/components/UserMenu"; const navigation = [ { name: "Boards", href: "/boards", icon: boardsIcon, current: true }, @@ -14,7 +14,9 @@ const navigation = [ export default async function Layout(props: { children: React.ReactNode }) { const session = await auth(); - if (!session?.user) redirect("api/auth/signin"); + if (!session?.user) { + redirect("/api/auth/signin"); + } return (
@@ -42,32 +44,11 @@ export default async function Layout(props: { children: React.ReactNode }) { ))}
- + -
{props.children}
diff --git a/src/app/_components/modal.tsx b/src/app/components/modal.tsx similarity index 100% rename from src/app/_components/modal.tsx rename to src/app/components/modal.tsx