supertokens / supertokens-website

Frontend SDK for SuperTokens - for session management + automatically refreshing sessions
https://supertokens.com
Other
54 stars 13 forks source link

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

Closed KitsuneKenshi closed 2 years ago

KitsuneKenshi commented 2 years ago

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.

rishabhpoddar commented 2 years ago

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