I’ve got a strange issue where my auth seems to be working correctly on the front-end but all of my backend requireAuth() calls are returning auth in a “loading” state.
Here’s my auth context on the front-end:
And here’s the PrivatePageLoader component’s auth context:
@dthyresson yes the user is returned as expected which makes things even more confusing No matter what when I console context.currentUser it’s always empty.
Have you tried using the useAuth() hook to fetch currentuser or userMetadata as per
API
The following values are available from the useAuth hook:
currentUser: An object containing information about the current user as set on the api side, or null if the user is not authenticated.
userMetadata: An object containing the user's metadata (or profile information) fetched directly from an instance of the auth provider client, or null if the user is not authenticated.
as as shown in the tutorial:
import { Link, routes } from '@redwoodjs/router'
import { useAuth } from '@redwoodjs/auth'
const BlogLayout = ({ children }) => {
const { logIn, logOut, isAuthenticated, currentUser } = useAuth()
return (
<div>
<h1>
<Link to={routes.home()}>Redwood Blog</Link>
</h1>
<nav>
<ul>
<li>
<Link to={routes.about()}>About</Link>
</li>
<li>
<Link to={routes.contact()}>Contact</Link>
</li>
<li>
<button onClick={isAuthenticated ? logOut : logIn}>
{isAuthenticated ? 'Log Out' : 'Log In'}
</button>
</li>
{isAuthenticated && <li>{currentUser.email}</li>}
</ul>
</nav>
<main>{children}</main>
</div>
)
}
export default BlogLayout
```
?
You may want `userMetadata` instead.
You can then set the result and `console.log(currentUser)` or `console.log(userMetadata)`.