The `nuxt-auth-auto-refresh` package provides automatic, periodic token refreshing for applications using the Nuxt Auth Module v5 (`@nuxtjs/auth-next`). Unlike the default Nuxt Auth v5 behavior, which only refreshes tokens immediately before API requests, this module actively monitors token expiration in the background. It polls every 500ms and triggers a refresh if a token is nearing its expiration (specifically, past 75% of its lifetime but not fully expired). This prevents users from being logged out unexpectedly during long sessions without API interaction or when tokens have very short lifespans. The current stable version is 1.0.2. Its release cadence is tied to the Nuxt Auth Module v5, which the README notes is not yet considered stable itself. This module differentiates by proactively managing token validity, enhancing user experience in specific scenarios.
npm install nuxt-auth-auto-refreshVerified import paths — ran on the pinned version, not inferred.
This configuration snippet demonstrates how to integrate `nuxt-auth-auto-refresh` into your `nuxt.config.js` by adding its distribution path to the `auth.plugins` array. This setup enables periodic token refreshes for your Nuxt Auth v5 application, preventing premature user logouts.
Regularly check the compatibility of `nuxt-auth-auto-refresh` with new versions of `@nuxtjs/auth-next`. Be prepared for potential refactoring if underlying Nuxt Auth APIs change significantly.
Thoroughly test token refresh functionality in production-like environments before relying on it, especially in critical applications with high uptime requirements.
Monitor `@nuxtjs/auth-next` updates for changes to internal token refresh mechanisms. If significant internal changes occur without official support, consider contributing to `@nuxtjs/auth-next` or forking this module for adaptation.
Verify that `nuxt-auth-auto-refresh` is installed in `node_modules` and the `src` path in `auth.plugins` is exactly `node_modules/nuxt-auth-auto-refresh/dist/index.js`.
Ensure your Nuxt Auth strategy includes a `refreshToken` endpoint and that your access tokens correctly contain `exp` (expiration) and `iat` (issued at) claims for the plugin to function as expected.