By Sam
Hi all,
I have a Nuxt 3 frontend and Django backend deployed on DigitalOcean App platform. Authentication is implemented using HttpOnly cookies, and the application works correctly locally. However, in the production environment, when a user refreshes the page, there is a slight delay during which it appears as though the user is not logged in.
// /plugins/auth.ts
import { useAuthUser } from "../composables/useAuthUser"
export default defineNuxtPlugin(async () => {
const user = useAuthUser()
if(!user.value) {
const { fetchUser } = useAuth();
await fetchUser();
}
});
Tested with Node.js versions 16.x and 20.x. The issue persists with both versions.
"engines": {
"node": "20.x"
}
Thank you for any insights or suggestions provided.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hey Sam,
This sounds like a hydration mismatch issue on page load, it happens when auth state is fetched async and the initial render doesn’t have it yet.
Since you’re using HttpOnly cookies, the client can’t read them directly, so useAuthUser() likely returns null on the first render, and only updates after fetchUser() completes. That delay is what causes the “not logged in” flash.
One way to reduce the flicker is to handle the user fetch during server-side rendering (if you’re not already), or delay rendering parts of the UI that depend on the auth state until fetchUser() completes.
Not 100% sure if it’s Nuxt config or timing-related, but might be worth double-checking how and when fetchUser() is called on the server vs client.
- Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.