sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.24k stars 161 forks source link

Adding headers to endpoint requests #838

Open AidosMarcos opened 1 month ago

AidosMarcos commented 1 month ago

Context

using nuxt-auth with local external provider and my external API demans an 'ApiKey' header to authorize any request to be made. So far i was unable to find a way to had custom header to the endpoints defined in nuxt-auth config, Is there any way to do this?

Already tried creating plugin trying to "catch" fetch request and manually add header but does not seem to work with fetch call made by nuxt-auth.

Describe the feature

Possibility to add request headers to defined endpoints.

How would you implement this?

Add another prop do the object that defines endpoint like:

endpoints: { signIn: { path: 'login', method: 'post', headers: { ... } }, signOut: { path: 'logout', method: 'post', headers: { ... } }, signUp: { path: 'register', method: 'post', headers: { ... } }, getSession: { path: 'session', method: 'get', headers: { ... } }, }

Additional information

Provider

phoenix-ru commented 1 month ago

Thank you for the issue. I've been in general considering if we could add something similar to AuthJS callbacks so that any developers are able to customize all the aspects of the outgoing request for a local/refresh provider. It seems to be quite a requested feature in one way or another.

I will give it some thought and try to come up with a good extensible solution similar to refreshHandler but more flexible

clcoco commented 1 month ago

Thank you for the issue. I've been in general considering if we could add something similar to AuthJS callbacks so that any developers are able to customize all the aspects of the outgoing request for a local/refresh provider. It seems to be quite a requested feature in one way or another.

I will give it some thought and try to come up with a good extensible solution similar to refreshHandler but more flexible

Would it be possible to also add the solutions proposed by @AidosMarcos for simpler and more straightforward use-cases (ie. to support httpOnly cookies)? I can work on it today if it's not a problem

phoenix-ru commented 3 weeks ago

Related issue: #722