Hello. If I create a instance of axios, supertoken is not detecting session cookies. I am using supe...
s
Hello. If I create a instance of axios, supertoken is not detecting session cookies. I am using supertokens-web-js in nuxt.js 2 // Here is my code plugins/axios-cache-setup.js
Copy code
import axios from 'axios'
import { setupCache } from 'axios-cache-interceptor/dev'

export default function ({ $config }, inject) {
  // Create axios instance
  const axiosInstance = axios.create({
    baseURL: $config.baseURL, 
  })
   // Set up caching
  // Set axios instance to Nuxt context
  const axiosWithCache = setupCache(axiosInstance, {
    methods: ['get', 'post'],
    debug: console.log,
  })

  inject('axiosCache', axiosWithCache)
}
r
hey @soumya0373 are you doing supertokens.init before making the axios instance?
s
yes
r
can you enable debug logs on the frontend and show the output when you make an api call using this axios instance?
s
sure
Now, cookies is getting passed
however it's returning html response
Copy code
<template>
  <div>
    <div v-if="loading">Loading..</div>
    <div v-else>{{ data }}</div>
  </div>
</template>

<script>
import axios from 'axios'
import { setupCache } from 'axios-cache-interceptor/dev'
const axiosInstance = axios.create()

const axiosWithCache = setupCache(axiosInstance, {
  debug: console.log,
})

export default {
  layout: 'navbar',

  data() {
    return {
      data: null,
      loading: false,
    }
  },

  mounted() {
    this.fetchProjects()
  },
  methods: {
    async fetchProjects() {
      this.loading = true

      this.data = await axiosWithCache.get(
        '/api/project/all?limit=12&start_at=' + 1 + '&search_key='
      )
      this.loading = false
    },
  },
}
</script>
What could be the issue?
r
not sure. I cant help this way with just code snippets from you
can you enable frontend debug logs and show the output? As i had requested before
s
How do I do that? Plase help
got it
17 Views