post urlencoded to login
hi, I need to POST url encoded username/password to login for for some reason auth is intercepting the login and failing
the config looks like:
export default defineNuxtConfig({
// ...
auth: {
// middleware
globalMiddleware: true,
strategies: {
local: {
scheme: 'refresh',
token: {
property: 'access_token',
},
endpoints: {
login: {
url: `${apiPrefix}/auth/token`,
method: 'post',
},
logout: {
url: `${apiPrefix}/auth/me`,
method: 'delete',
},
refresh: {
url: `${apiPrefix}/auth/refresh`,
method: 'post',
},
user: {
url: `${apiPrefix}/auth/me`,
method: 'get',
},
},
user: {
property: '',
autoFetch: true,
},
},
},
},
but in $auth login and refresh are replaced with /_auth/local/local/authorize which dies with Invalid JSON body if I url encode the body.
const res = await $auth.loginWith('local', {
body: encodeURIComponent(state),
Headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
});
any suggestion about what I'm missing?
- Operating System: Linux
- Node Version: v18.19.1
- Nuxt Version: 3.10.3
- CLI Version: 3.10.1
- Nitro Version: 2.9.1
- Package Manager: [email protected]
- Builder: -
- User Config: srcDir, telemetry, devtools, extends, modules, eslint, fontMetrics, googleFonts, typescript, runtimeConfig, auth, routeRules, vite
- Runtime Modules: @nuxtjs/[email protected], @nuxtjs/[email protected], @nuxtjs/[email protected], @nuxt/[email protected], [email protected], @nuxt-alt/[email protected], @pinia/[email protected]
- Build Modules: -
I have this issue, too,
What I did is set stategy.ssr = false I got this work correct ( I read what developer write inside module, I got his point.) If you use ssr:true, don't need it.
Thanks developer so much!
this problem became critical for me as I use nuxt generate and this hardcoded authorize thing doesn't exist unless nitro is running.
at least for the local/refresh strategy adding ssr: false makes no change :sob:
I'm not sure if it helps, but it works for me
const response = await $auth.loginWith("cookie", {
body: new URLSearchParams(state)
})
I added JSON support to the backend at the end, but now my main problem is that this authorize interceptor doesn't exist when using nuxt generate and that means I can't log in. any suggestion on how to disable it when using local?