General options shared with all strategies. See moduleDefaults in options.ts for defaults.

globalMiddleware

Additional Information

  • Default: false
Enables/disables the middleware to be used globally.

enableMiddleware

Additional Information

  • Default: true
Enables/disables the built-in middleware.

redirect

Additional Information

Example:

auth: {
    redirect: {
        login: (auth, trans) => trans('/login'),
        logout: auth => auth.ctx.$localePath('/login'),
        callback: () => '/login',
        home: '/'
    }
}

Note: If @nuxtjs/i18n is installed, the redirects will automatically be processed through it if they are strings. If you would like to prevent this, cast it as a function to return the string like the callback property in the example above.
The properties all have access to the auth instance and localPath when cast as a function.
login
User will be redirected to this path if login is required.
logout
User will be redirected to this path if after logout, current route is protected.
home
User will be redirected to this path after login. (rewriteRedirects will rewrite this path)
callback
User will be redirected to this path by the identity provider after login. (Should match configured Allowed Callback URLs (or similar setting) in your app/client with the identity provider)Each redirect path can be disabled by setting to false. Also you can disable all redirects by setting redirect to false

watchLoggedIn

Additional Information

  • Default: true
When enabled (default) user will be redirected on login/logouts.

tokenValidationInterval

Additional Information

  • Default: false
If set to true, default interval is 1000ms, otherwise set time in milliseconds. This is how often the module with attempt to validate the token for expiry.
This option is experimental.

stores

Additional Information

Default:

auth: {
    stores: {
        state: {
            namespace: 'auth'
        },
        pinia: {
            enabled: false,
            namespace: 'auth',
        },
        cookie: {
            enabled: true,
            prefix: 'auth.',
            options: {
                path: '/',
                sameSite: 'lax',
                maxAge: 31536000,
            },
        },
        local: {
            enabled: false,
            prefix: 'auth.',
        },
        session: {
            enabled: false,
            prefix: 'auth.',
        }, 
    }
}
state
  • namespace - Nuxt's useState key name. This will be used if pinia is disabled.
pinia
  • namespace - Pinia's store key name.
  • enabled - whether or not to enable pinia to handle stateamanement.
  • prefix - Default token prefix used in building a key for token storage in the browser's localStorage.
  • enabled - wheter or not to enable cookie storage
options
Additional cookie options, passed to cookie.

Options Info

path
path where the cookie is visible. Default is '/'.
expires
can be used to specify cookie lifetime in Number of days or specific Date. Default is session only.
maxAge
Specifies the number (in seconds) to be the value for the Max-Age (preferred over expires)
domain
domain (and by extension subdomain/s) where the cookie is visible. Default is domain and all subdomains.
secure
sets whether the cookie requires a secure protocol (https). Default is false, should be set to true if possible.


Note: Using cookies is effectively required for universal mode (SSR) apps because authentication on first page load occurs only on the server side and local storage is not available on the server.You can disable use of cookie storage by setting cookie.enabled to false
local
  • enabled - whether or not to enable localSotrage
  • prefix - Default token prefix used in building a key for token storage in the browser's localStorage.
session
  • enabled - whether or not to enable localSotrage
  • prefix - Default token prefix used in building a key for token storage in the browser's localStorage.

plugins

Additional Information

If you have any nuxt plugin that depends on $auth you have to specify it here instead of top-level plugins option in nuxt.config.js. See Extending Auth Plugin

resetOnError

Additional Information

  • Default: false
Either a boolean or a function is accepted. If a function is passed, it will take the same arguments as onError handlers and return Boolean to inform whether a reset should be performed.If enabled, user will be automatically logged out if an error happens. (For example when token expired)

resetOnResponseError

Additional Information

  • Default: false
Either a boolean or a function is accepted. If a function is passed, you can apply your own logic to what happens when the error occurs from a response.
auth: {
    //... module options
    resetOnResponseError: (error, auth, scheme) => {
       if (error?.response?.status === 401) {
           scheme.reset?.()
           auth.redirect('login')
       }
   },
}
If enabled, user will be automatically logged out if an error happens. (For example when token expired)

rewriteRedirects

Additional Information

  • Default: true
If enabled, user will redirect back to the original guarded route instead of redirect.home.

fullPathRedirect

Additional Information

Default: falseIf true, use the full route path with query parameters for redirect

redirectStrategy

Additional Information

  • Default: storage
The type of redirection strategy you want to use, storage utilizng localStorage for redirects, query utilizing the route query parameters.