Open SaraBMo opened 7 months ago
Hi @SaraBMo :wave:
That's indeed a limitation we've identified. We talk about it in the following discussion: https://github.com/orgs/fief-dev/discussions/292
I've a few ideas to improve this.
@frankie567 @SaraBMo and i are working on the same project using fief-js; as you were asking for help, maybe you could expose the idea you got to improve it ?
Came here tonight to report the same thing 👍
I'm running into this issue as well 💀
I've started to work on this here: https://github.com/fief-dev/fief-js/pull/10
This will also be the occasion to spin up a complete example for Next.js App Router.
+1 on this issue, I'm struggling a bit to handle Fief with the app routing, as I'm unable to retrieve the access token despite being authenticated Happy to see it's gonna be taken care of!
Describe the bug
In NextJS, client-side, you cannot distinguish between not-yet authenticated and unauthenticated. Client-side, you are using the current user and token hooks populated by FiefAuthProvider. Problem is, on page load, you get null values, that will either get populated with the user info when the request to /current-user resolves and fills in the context, or simply never be changed if the user is unauthenticated. That causes issues as we use fief to authenticate our external api calls, and is inelegant for showing user information (Flashes log in before showing user info, instead of a loading state).
The solution I propose is simple, but can be discussed of course : have the context provide an initial value to indicate loading, and only go null when we know user is unauthenticated.
Related to : https://github.com/orgs/fief-dev/discussions/292
To Reproduce
Steps to reproduce the behavior:
Expected behavior
An authenticated user first loading the page should be distinguishable from an unauthenticated user.
Configuration