auth icon indicating copy to clipboard operation
auth copied to clipboard

post urlencoded to login

Open amery opened this issue 1 year ago • 6 comments

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?



amery avatar Mar 07 '24 20:03 amery

I have this issue, too, image

vathsathya avatar Apr 01 '24 09:04 vathsathya

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.

image

image image

image

vathsathya avatar Apr 01 '24 09:04 vathsathya

Thanks developer so much!

vathsathya avatar Apr 01 '24 09:04 vathsathya

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:

amery avatar Apr 01 '24 16:04 amery

I'm not sure if it helps, but it works for me

const response = await $auth.loginWith("cookie", {
      body: new URLSearchParams(state)
    })

vvatlin avatar Apr 15 '24 13:04 vvatlin

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?

amery avatar Apr 17 '24 22:04 amery