From df6310f1c71e71181f6fb7c70e6233a2097ff892 Mon Sep 17 00:00:00 2001 From: Weronika Tomaszewska Date: Mon, 18 Dec 2023 18:18:52 -0500 Subject: [PATCH] feature/CPF-34 add currentUser fix by @as1729, display email of the current user in the navbar --- api/src/lib/auth.ts | 17 ++++++----------- .../AuthenticatedLayout.tsx | 18 +++--------------- web/src/pages/LoginPage/LoginPage.tsx | 2 -- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/api/src/lib/auth.ts b/api/src/lib/auth.ts index 77708384..b70912ed 100644 --- a/api/src/lib/auth.ts +++ b/api/src/lib/auth.ts @@ -1,4 +1,4 @@ -import { parseJWT, Decoded } from '@redwoodjs/api' +import { Decoded } from '@redwoodjs/api' import { AuthenticationError, ForbiddenError } from '@redwoodjs/graphql-server' /** @@ -32,17 +32,12 @@ type RedwoodUser = Record & { roles?: string[] } export const getCurrentUser = async ( decoded: Decoded ): Promise => { - if (!decoded) { - return null + console.log(decoded) + return { + id: 'unique-user-id', + email: 'email@example.com', + roles: ['admin'], } - - const { roles } = parseJWT({ decoded }) - - if (roles) { - return { ...decoded, roles } - } - - return { ...decoded } } /** diff --git a/web/src/layouts/AuthenticatedLayout/AuthenticatedLayout.tsx b/web/src/layouts/AuthenticatedLayout/AuthenticatedLayout.tsx index 40d0e9a8..6c954bcb 100644 --- a/web/src/layouts/AuthenticatedLayout/AuthenticatedLayout.tsx +++ b/web/src/layouts/AuthenticatedLayout/AuthenticatedLayout.tsx @@ -10,7 +10,7 @@ type AuthenticatedLayoutProps = { } const AuthenticatedLayout = ({ children }: AuthenticatedLayoutProps) => { - const { isAuthenticated, currentUser, logOut } = useAuth() + const { currentUser, isAuthenticated, logOut } = useAuth() return (
@@ -21,19 +21,7 @@ const AuthenticatedLayout = ({ children }: AuthenticatedLayoutProps) => {
- {/* Replace the code below when authentication is complete */} -
email@email.com
- - - {/* Use the code below for conditional currentUser logic */} - {/* {isAuthenticated && ( + {isAuthenticated && ( <>
{currentUser.email}
- )} */} + )}
diff --git a/web/src/pages/LoginPage/LoginPage.tsx b/web/src/pages/LoginPage/LoginPage.tsx index 56312fa8..2287b15b 100644 --- a/web/src/pages/LoginPage/LoginPage.tsx +++ b/web/src/pages/LoginPage/LoginPage.tsx @@ -1,5 +1,3 @@ -import { useAuth } from 'web/src/auth' - import { Link, routes } from '@redwoodjs/router' import { MetaTags } from '@redwoodjs/web'