Closed dreftas closed 3 weeks ago
@dreftas
You're correct—currently, there isn't an option to set a custom header directly with the login() function.
Thanks for pointing this out! I'll be adding this feature soon to make it easier to set headers like Accept-Language
for localized responses and validation messages.
In the meantime, you can use useSanctumFetch()
, which accepts options as a second argument (just like the ofetch
client).
Thanks again for your feedback, and I’ll keep you updated on the new feature!
Thanks @hkp22 :)
Hey, as I can see v0.1.15 allows to set custom options to login()
function, thanks a lot! :)
@dreftas
We’ve just released v0.1.15
, which includes this new feature! Now, in the login()
function, you can use the second argument to pass ofetch
client options, allowing you to set custom headers as needed.
Here’s an example:
await login(userCredentials, {
headers: {
'custom-header': 'value'
}
});
For more details on the login
function and its features, please check out the documentation here: Nuxt Sanctum Authentication - login.
Thanks for your input—it helped us improve the module!
I can't find any information in documentation.
How we can set some custom header to
login()
function ?For example to use some
Accepted-Language
header to set it to Nuxt locale (which can be changed by user), so by that we know in Laravel app which locale to use for errors validation or something similar that has translations from backend).As I understand (but not tested)
useSanctumFetch()
has this possibility because it accepts second argument as options in which we can pass headers and other information (documentation states:use it as you would with a regular ofetch client
).