nuxt-alt / auth

An alternative module to @nuxtjs/auth
https://nuxt-alt-auth.vercel.app/
MIT License
112 stars 20 forks source link

post urlencoded to login #112

Open amery opened 8 months ago

amery commented 8 months ago

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?


vathsathya commented 7 months ago

I have this issue, too, image

vathsathya commented 7 months ago

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 commented 7 months ago

Thanks developer so much!

amery commented 7 months ago

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:

vvatlin commented 7 months ago

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

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

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?