Question

Nuxt 3 app using Httponly cookies losing authentification after page refresh

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();
    }
});

  1. The issue is specifically observed during page refresh in the production environment.
  2. The authentication state, managed by HttpOnly cookies, appears to resolve with a slight delay, leading to a brief period where it seems the user is not logged in.
  3. The problem does not occur in the local development environment.

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.


Submit an answer


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!

Sign In or Sign Up to Answer

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel