supertokens / supertokens-website

Frontend SDK for SuperTokens - for session management + automatically refreshing sessions

Home Page:https://supertokens.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Token refreshing is not working with @nuxtjs/axios (401 response)

KitsuneKenshi opened this issue · comments

Using
Nuxt.js - 2.15.8
@nuxtjs/axios - 5.13.6
SuperTokens-website - 10.0.5
SuperTokens-node - 8.2.0

Problem
Creating Axios instance from @nuxtjs/axios and adding supertoken Interceptor is breaking, causing token refreshing to work incorrectly. Interceptors are getting added after first request.

Code
/plugins/axios.js

import SuperTokens from 'supertokens-website';

export default function ({ $axios, $config }, inject) {
  // Create a custom axios instance
  const axiosInstance = $axios.create({
    baseURL: $config.root,
  });

  // Add SuperTokens interceptors
  SuperTokens.addAxiosInterceptors(axiosInstance);

  // Inject to context as $axios
  inject('axios', axiosInstance);
} 

nuxt.config.js

plugins: ['~/plugins/axios']

Solution for users
Using Axios from Axios package (not from @nuxtjs/axios) and injecting it into Nuxt.js context fixes the issue.

Thanks @Kall7 . Since you have also given a solution, I am closing this issue.