-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature/CPF-34 add currentUser fix by @as1729, display email of the c…
…urrent user in the navbar
- Loading branch information
Showing
3 changed files
with
9 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
|
||
/** | ||
|
@@ -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 } | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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%' }}> | ||
|
@@ -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 | ||
|
@@ -45,7 +33,7 @@ const AuthenticatedLayout = ({ children }: AuthenticatedLayoutProps) => { | |
Logout | ||
</Button> | ||
</> | ||
)} */} | ||
)} | ||
</div> | ||
</nav> | ||
<Navigation /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters