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

Is there a way to make authenticated requests out of the box? #688

Open
1 of 5 tasks
PaulCombal opened this issue Feb 27, 2024 · 1 comment
Open
1 of 5 tasks

Is there a way to make authenticated requests out of the box? #688

PaulCombal opened this issue Feb 27, 2024 · 1 comment
Labels

Comments

@PaulCombal
Copy link

PaulCombal commented Feb 27, 2024

Describe the feature

I successfully managed to log in with Nuxt Auth!

Now I want to query my API from the client with a REST request using the Authentication: Bearer token header.

I know Nuxt-Auth does this under the hood to get the context, right after logging in.

Does Nuxt Auth also provide a way to make our own authenticated requests? In the docs we have this example:

<script setup lang="ts">
const headers = useRequestHeaders(['cookie']) as HeadersInit
const { data: token } = await useFetch('/api/token', { headers })
</script>

Is this all? Is there a composable, or is this out of this library's scope? Is this the recommended way to make authenticated requests within the whole application?

Thank you

How would you implement this?

No response

Additional information

  • Would you be willing to help implement this feature?

Provider

  • AuthJS
  • Local
  • Refresh
  • New Provider
@PaulCombal PaulCombal added enhancement An improvement that needs to be added pending labels Feb 27, 2024
@DavidDeSloovere
Copy link

The docs say you have to pass the cookie explicitly for SSR, but it works without. I think Nuxt changed the default.

In the api, you can get the session or token with the composables, and you have enough to know who is making the call.
Unless your API is not in the nuxt application.

@zoey-kaiser zoey-kaiser added question and removed enhancement An improvement that needs to be added pending labels Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants