From d509f7a76d6f3e33ea0074bd256754d13850c5e4 Mon Sep 17 00:00:00 2001 From: Simon Knittel Date: Sun, 24 Mar 2024 12:00:51 +0100 Subject: [PATCH] feat: Work on CmdK --- app/src/app/(app)/_components/Sidebar.tsx | 2 +- .../dashboard/_components/ProfileTile.tsx | 5 ++-- app/src/app/_components/CmdK.tsx | 23 +++++++++++++++++++ app/src/server/auth.ts | 4 +++- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/app/(app)/_components/Sidebar.tsx b/app/src/app/(app)/_components/Sidebar.tsx index bdb9c744..9d72e2a0 100644 --- a/app/src/app/(app)/_components/Sidebar.tsx +++ b/app/src/app/(app)/_components/Sidebar.tsx @@ -24,7 +24,7 @@ export const Sidebar = async () => {
- +
) : null} - {entity && ( + {authentication.session.entityId && ( diff --git a/app/src/app/_components/CmdK.tsx b/app/src/app/_components/CmdK.tsx index b259b9c3..5aea4901 100644 --- a/app/src/app/_components/CmdK.tsx +++ b/app/src/app/_components/CmdK.tsx @@ -3,6 +3,7 @@ import { useRouter } from "next/navigation"; import { useEffect, useState, type Dispatch, type SetStateAction } from "react"; import { FaCog, FaHome, FaLock, FaUsers } from "react-icons/fa"; import { MdWorkspaces } from "react-icons/md"; +import { RiSpyFill } from "react-icons/ri"; import useAuthentication from "~/_lib/auth/useAuthentication"; import "./CmdK.css"; @@ -81,6 +82,28 @@ export const CmdK = ({ open, setOpen }: Props) => { )} + {authentication.authorize([ + { + resource: "citizen", + operation: "read", + }, + ]) && ( + + { + router.push( + `/spynet/entity/${authentication.session.entityId}`, + ); + setOpen(false); + }} + > + + Eigenes Profil öffnen + + + )} + {(authentication.authorize([ { resource: "user", diff --git a/app/src/server/auth.ts b/app/src/server/auth.ts index 8362f575..51f80ae0 100644 --- a/app/src/server/auth.ts +++ b/app/src/server/auth.ts @@ -75,6 +75,7 @@ declare module "next-auth" { } & DefaultSession["user"]; discordId: string; givenPermissionSets: PermissionSet[]; + entityId: string | null; } interface User { @@ -154,7 +155,8 @@ export const authOptions: NextAuthOptions = { emailVerified: user.emailVerified, }, discordId: discordAccount!.providerAccountId, - givenPermissionSets: givenPermissionSets, + givenPermissionSets, + entityId: entity?.id, }; },