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.31k stars 164 forks source link

feat: Add a composable to make authenticated requests #787

Closed itsmohmans closed 3 months ago

itsmohmans commented 4 months ago

๐Ÿ”— Linked issue

688

โ“ Type of change

๐Ÿ“š Description

Add authFetch composable to provide a way to manually fetch a resource with authorization headers.

๐Ÿ“ Checklist

zoey-kaiser commented 4 months ago

Hi @itsmohmans ๐Ÿ‘‹

Thank you for your contribution! While I think it is really cool to add these kinds of utilities to the module, I think we should approach it slightly differently:

Let us provide a more generic: headers computed that only returns the required headers for the request. This would allow people to use the utility for other HTTP clients such as Axios. It would also avoid us having to hard-depend on the Nuxt $fetch methods and allow users to choose between using $fetch, useFetch, or useAsyncData without us writing custom wrappers for each.

Alternatively, if we did want to add custom wrappers for the fetch functions of Nuxt I would propose adding a new composable to handle this.

I will also pull in @phoenix-ru for his opinion on this matter!

itsmohmans commented 4 months ago

Hey @zoey-kaiser! I agree it should be more generic; However, wouldn't a headers computed be somewhat similar to the current token property as we can just add it to the request headers along with anything else we want to add in the request?

I still do think the module needs a composable that makes authenticated requests out of the box, but I'm open for edits on how we approach this in a better way in order to work well with all other tools as well.

zoey-kaiser commented 3 months ago

Hi @itsmohmans ๐Ÿ‘‹

I would propose we close this Pull request and discuss some of the options we outlined above in #688. Like I mentioned beforehand, I generally do like this idea, however would like to ensure we add this correctly and provide as much utility as possible!

Therefore, let's go back to the drawing board and discuss some new options ๐Ÿ˜Š