nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

Add headers for local strategy in SignIn

Open dangercris opened this issue 2 years ago • 1 comments

Describe the feature

We need to enhance the sign-in functionality to support custom headers in the login request. Currently, the headers parameter (signInHeaders) is optional and defaults to an empty object if not provided. However, we require the ability to pass specific headers during the sign-in process, which might be necessary for various use cases like API versioning, custom authentication tokens, or additional security measures.

const signIn: SignInFunc<Credentials, any> = async (credentials, signInOptions, signInParams) => {
  const nuxt = useNuxtApp()

  const runtimeConfig = await callWithNuxt(nuxt, useRuntimeConfig)
  const config = useTypedBackendConfig(runtimeConfig, 'local')
  const { path, method } = config.endpoints.signIn
  const response = await _fetch<Record<string, any>>(nuxt, path, {
    method,
    body: credentials,
    params: signInParams ?? {}
  })
}

How would you implement this?

Proposed Changes

  • Add Custom Headers: Ensure that custom headers can be passed into the signInHeaders parameter and included in the request. This will allow more flexibility for the client-side application to communicate with the backend.
  • Documentation: Update the documentation to reflect the inclusion of custom headers, including examples of how to use them effectively.
  • Testing: Implement unit and integration tests to verify that the headers are correctly passed and processed during the sign-in request.

Benefits

  • Flexibility: Enables the passing of custom headers, which can be crucial for meeting specific security and configuration requirements.
  • Scalability: Improves the scalability of the sign-in mechanism by allowing additional customization points without altering the core functionality.
  • Security: Supports the implementation of advanced security features by allowing headers to carry necessary authentication or verification tokens.

Additional information

  • [X] Would you be willing to help implement this feature?

Provider

  • [ ] AuthJS
  • [X] Local
  • [ ] Refresh
  • [ ] New Provider

dangercris avatar Aug 23 '24 17:08 dangercris

Released in @sidebase/[email protected]

zoey-kaiser avatar Aug 25 '24 16:08 zoey-kaiser