Skip to content

Commit

Permalink
feature/CPF-34 add currentUser fix by @as1729, display email of the c…
Browse files Browse the repository at this point in the history
…urrent user in the navbar
  • Loading branch information
Vikariusu committed Dec 18, 2023
1 parent 37b340b commit df6310f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
17 changes: 6 additions & 11 deletions api/src/lib/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseJWT, Decoded } from '@redwoodjs/api'
import { Decoded } from '@redwoodjs/api'
import { AuthenticationError, ForbiddenError } from '@redwoodjs/graphql-server'

/**
Expand Down Expand Up @@ -32,17 +32,12 @@ type RedwoodUser = Record<string, unknown> & { roles?: string[] }
export const getCurrentUser = async (
decoded: Decoded
): Promise<RedwoodUser | null> => {
if (!decoded) {
return null
console.log(decoded)
return {
id: 'unique-user-id',
email: '[email protected]',
roles: ['admin'],
}

const { roles } = parseJWT({ decoded })

if (roles) {
return { ...decoded, roles }
}

return { ...decoded }
}

/**
Expand Down
18 changes: 3 additions & 15 deletions web/src/layouts/AuthenticatedLayout/AuthenticatedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type AuthenticatedLayoutProps = {
}

const AuthenticatedLayout = ({ children }: AuthenticatedLayoutProps) => {
const { isAuthenticated, currentUser, logOut } = useAuth()
const { currentUser, isAuthenticated, logOut } = useAuth()

return (
<div className="container-fluid" style={{ width: '90%' }}>
Expand All @@ -21,19 +21,7 @@ const AuthenticatedLayout = ({ children }: AuthenticatedLayoutProps) => {
</Link>
</div>
<div className="col d-flex justify-content-end">
{/* Replace the code below when authentication is complete */}
<div className="navbar-text">[email protected]</div>
<Button
size="sm"
variant="link"
className="nav-link navbar-text mx-2"
onClick={logOut}
>
Logout
</Button>

{/* Use the code below for conditional currentUser logic */}
{/* {isAuthenticated && (
{isAuthenticated && (
<>
<div className="navbar-text">{currentUser.email}</div>
<Button
Expand All @@ -45,7 +33,7 @@ const AuthenticatedLayout = ({ children }: AuthenticatedLayoutProps) => {
Logout
</Button>
</>
)} */}
)}
</div>
</nav>
<Navigation />
Expand Down
2 changes: 0 additions & 2 deletions web/src/pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useAuth } from 'web/src/auth'

import { Link, routes } from '@redwoodjs/router'
import { MetaTags } from '@redwoodjs/web'

Expand Down

0 comments on commit df6310f

Please sign in to comment.