Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding headers to endpoint requests #838

Open
2 of 5 tasks
AidosMarcos opened this issue Aug 1, 2024 · 5 comments
Open
2 of 5 tasks

Adding headers to endpoint requests #838

AidosMarcos opened this issue Aug 1, 2024 · 5 comments
Labels
enhancement An improvement that needs to be added p2 Nice to have

Comments

@AidosMarcos
Copy link

AidosMarcos commented Aug 1, 2024

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

  • Would you be willing to help implement this feature?

Provider

  • AuthJS
  • Local
  • Refresh
  • New Provider
@AidosMarcos AidosMarcos added enhancement An improvement that needs to be added pending An issue waiting for triage labels Aug 1, 2024
@phoenix-ru
Copy link
Collaborator

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

@phoenix-ru phoenix-ru added p2 Nice to have and removed pending An issue waiting for triage labels Aug 1, 2024
@clcoco
Copy link

clcoco commented Aug 2, 2024

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
Copy link
Collaborator

Related issue: #722

@blparker
Copy link

blparker commented Oct 2, 2024

Not sure if this is helpful, but I am using the signIn method:

const { signIn } = useAuth();

And, in looking at the code, there is a signInHeaders parameter that sets the headers:

const signIn: SignInFunc<Credentials, any> = async (credentials, signInOptions, signInParams, signInHeaders) => {
...
}

You should be able to call it with:

await signIn(creds, {}, {}, {
    'X-ApiKey': '1234'
});

@asugomez
Copy link

asugomez commented Oct 10, 2024

I'm also facing with this issue, this solution would solve most of my problems 🤞🏼 (my developer problems)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement that needs to be added p2 Nice to have
Projects
None yet
Development

No branches or pull requests

5 participants