nuxt-modules / security

🛡 Automatically configure your app to follow OWASP security patterns and principles by using HTTP Headers and Middleware
https://nuxt-security.vercel.app/
MIT License
829 stars 60 forks source link

How can I avoid 401 error with useFetch and http basic auth, when SWR enabled #548

Open lionel-addvanto opened 2 weeks ago

lionel-addvanto commented 2 weeks ago

Hello, I have the newest Nuxt (v3.14.159) and nuxt-security (v2.0.0) packages . When I call useFetch to a server route, in a page, where SWR is enabled, I get a 401 because of the http basic auth. When I manually include the headers in the request it works, but what is the Nuxt/nuxt-security intended way to do this?

Thank you and kind regards

Baroshem commented 2 weeks ago

Hey there,

The main intention behind Basic Auth in this module is to block accessing certain page/subpages but it also works for all server endpoints which does not render any route.

Have you maybe tried excluding this server route in exclude option? https://nuxt-security.vercel.app/documentation/middleware/basic-auth#exclude

There is also an issue for route based Basic Auth but it was not implemented yet - https://github.com/Baroshem/nuxt-security/issues/443. Maybe you would be interested in contributing? :)