Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

371
Views
How logout user when one of APIs responds Unauthorized 401 (Nuxt-Auth)

How logout user when one of APIs responds Unauthorized 401 with Nuxt-Auth? I use AXIOS & built-in functions of Nuxt-Auth for requests

My nuxt-config settings for nuxt-auth:

    auth: {
        redirect: {
            login: '/login',
            logout: '/',
            callback: '/login',
            home: '/panel/dashboard'
        },
        strategies: {
            local: {
                token: {
                    property: 'token',
                    global: true,
                    type: 'Bearer',
                    required: true,
                },
                user: {
                    property: 'user',
                    autoFetch: true
                },
                endpoints: {
                    login: {url: '/api/auth/login_verify', method: 'post'},
                    logout: {url: '/api/auth/logout', method: 'get'},
                    user: {url: '/api/auth/validate', method: 'get'},
                },
            },
        }
    },

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since you're using Axios, it'll be easy to use Interceptors and catch the error according to your requirement and then call the logout action

Something like below with a plugin created in src/plugins/axios.js will work

export default function ({ $axios }) {
  $axios.onError((error) => {
    if (error.response.status === 401) {
      CALL_LOGOUT_ACTION_HERE
    }
  })
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!