Denoder / nuxt-module-alternatives

Alternative modules to use while waiting for Nuxt 3 Compatibility
MIT License
144 stars 14 forks source link

form encoded cookie login #90

Closed amery closed 2 years ago

amery commented 2 years ago

Hi, noob question. on the ofetch powered auth, how should loginWith("cookie", ...args) be used some those args get multipart/form-data encoded?

if I understand correctly ...args becomes endpoint so on nuxt.config.ts I have

strategies: {
  cookie: {
    cookie: {
      server: true,
      name: "session-cookie-name",
    },    
    endpoints: {
      login: {
        url: `${apiPrefix}/login`,
        method: "post",
        headers: {
          "Content-Type": "multipart/form-data",
        },
      },
    ...
  },
}

and on login.vue

const app = useNuxtApp();

// form
interface Form {
  username: string;
  password: string;
  returnTo?: string;
}

const form = reactive<Form>({
  username: "",
  password: "",
});

const submitForm = ($event: Event) => {
  app.$auth.loginWith("cookie", { body: form });
  ...
}

but the form gets encoded as json instead. and when using { data: form } instead of body it doesn't send any payload with the POST. what am I doing wrong?

Thanks

Denoder commented 2 years ago

use:

app.$auth.loginWith('cookie', { 
    body: new URLSearchParams(form).toString(),
    headers: {
        'content-type': 'application/x-www-form-urlencoded',
    },
})
amery commented 2 years ago

Thank you