NextJS PWA app gets stuck at this screen
I have a project which I've converted to a PWA. We use Kinde for the auth of course. However, sometimes, when I open the app, it gets stuck at this screen. There is no button I can click and nothing I can do. It is stuck indefinitely. It feels like a auth page cause that is the only page that doesn't have the look and feel of our app.
From the logs I can see it opens up the base file "/". And that page uses this code:
const { isAuthenticated } = getKindeServerSession();
if (await isAuthenticated()) {
redirect("/welcome");
}
return (
<div className="flex flex-col md:flex-row h-dvh font-helvetica">
Home Page
</div>
)
There is no routing that happens after that so I'm guessing it is stuck at the isAuthenticated lines.
The funny thing is, if I give it sometime, the auth resolves itself and I get led straight into the app with my auth credentials correctly in place. Any idea or thoughts on how to debug this?
3 Replies
Okay did some testing by adding some logs:
const { isAuthenticated } = getKindeServerSession();
console.log("crossed the getKinderSerevrAction line");
if (await isAuthenticated()) {
console.log("in the if block of is auth on home");
redirect("/welcome");
}
It seems like it gets stuck at the redirect block. @KindeAI
Hmmm.. it seems I’m not enabled to reply in this channel. Please contact a team member for help.
Hey @Pranay,
Based on your description, this appears to be an authentication flow state issue that can occur in PWAs. Here are a few potential solutions:
1. Use Middleware Instead
Instead of checking authentication in the page component, consider using Next.js middleware for authentication checks :
2. Handle Loading State
In your current implementation, consider adding a loading state while authentication is being checked :
3. Client-Side Authentication Check
For PWAs, you might want to handle authentication checks on the client side :
4. Check Environment Variables
There's a known issue with authentication flow state in preview environments . Make sure your environment variables are correctly set, especially:
- KINDE_SITE_URL
- KINDE_POST_LOGIN_REDIRECT_URL
- KINDE_POST_LOGOUT_REDIRECT_URL
If you're still experiencing issues - let me know.