nuxt-alt / auth

An alternative module to @nuxtjs/auth
https://nuxt-alt-auth.vercel.app/
MIT License
96 stars 20 forks source link

Add Custom Header #58

Closed dtobi59 closed 1 year ago

dtobi59 commented 1 year ago

Hey guys, I am trying to add a custom header on every request going out from my nuxt app.

what I have done:

  1. created a file inside plugging dir -> fetch.ts
  2. wrote the code below

` export default defineNuxtPlugin(nuxtApp => {

console.log("Coimging frorm Plugin")

$http.setHeader("HTTP-REQUEST-SOURCE", 'web:1.0')

}) `

The code works but at the initial load of the dashboard page, it does not work. I then observed that nuxt-alt/auth is making a request to the user profile API before the ohfetch.ts plugin loads.

Please help, how do i overcome this?

dtobi59 commented 1 year ago

Solved by adding below code to nuxt.config.ts

 http:{

      credentials: 'include',
      headers: {
        accept: 'application/json, text/plain, */*',
        "custom-header-here": 'value',

      },
    }