Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post urlencoded to login #112

Open
amery opened this issue Mar 7, 2024 · 6 comments
Open

post urlencoded to login #112

amery opened this issue Mar 7, 2024 · 6 comments

Comments

@amery
Copy link

amery commented Mar 7, 2024

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
Copy link

I have this issue, too,
image

@vathsathya
Copy link

vathsathya commented Apr 1, 2024

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
Copy link

Thanks developer so much!

@amery
Copy link
Author

amery commented Apr 1, 2024

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 😭

@vvatlin
Copy link

vvatlin commented Apr 15, 2024

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

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

@amery
Copy link
Author

amery commented Apr 17, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants