Denoder / nuxt-module-alternatives

Alternative modules to use while waiting for Nuxt 3 Compatibility
MIT License
144 stars 14 forks source link

$fetch post/patch not using authorization header #112

Closed lowbits closed 2 years ago

lowbits commented 2 years ago

Environment

Reproduction

await $fetch("/api/v1/users", {
            method: "PATCH",
            body: {
                gender: gender?.name,
            },
        })
// .nuxt.config.ts

proxy: {
        enableProxy: true,
        proxies: {
            '/api': {
                target: 'http://localhost:4000',
                changeOrigin: true,
                rewrite: (path:string) => {
                    return path.replace(/^\/api/, '')
                }
            },
        },
        fetch: true
    },

    http: {
        debug: true,
        proxyHeaders: true,
        interceptorPlugin: true,
    },

Describe the bug

when is use $fetch() for a GET request, the authorization header is set but when im using $fetch('/url', {method: 'POST'}) there is no AUTHORIZATION HEADER in the request, and I get a 401. Did i miss something?

Additional context

No response

Logs

No response

Denoder commented 2 years ago

There isn't enough context for me to know what you're trying to accomplish. You say that there is no authorization header, but are you creating an interceptor with $fetch to handle that use case? All I'm seeing is a snippet of fetch being used. Please provide a minimal reproduction.

lowbits commented 2 years ago

Hey sorry for bothering you. I think I found the solution. So I switch from $fetch, to $http.$patch, the only problem I have now is $http.$patch is sending a HEADER METHOD 'patch', but the server only accepts 'PATCH', for $http.$post, $put, etc the method is sent in uppercase. Only the patch is not working.

Denoder commented 2 years ago

I've updated the http module

mittci commented 2 years ago

I've updated the http module

@Teranode that is refered to other methods too? That problem also is resolved https://github.com/Teranode/nuxt-module-alternatives/issues/106#issuecomment-1291640986?

Denoder commented 2 years ago

yes