nuxt-alt / auth

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

nothing is posted to backend with cookie strategy #27

Closed andreas-it-dev closed 1 year ago

andreas-it-dev commented 1 year ago

am in the middle of experimenting with this package, so the code is still a little rough and lots of hard coded stuff, please bear with me.

i am trying to establish a cookie based auth solution with a rails backend. this is the config part in nuxt.config.ts:

  auth: {
    strategies: {
      localStorage: false,
      cookie: {
        cookie: {
          server: true,
        },
        endpoints: {
          login: {
            url: 'http://localhost:3000/session',
            method: 'post',
          },
          logout: {
            url: 'http://localhost:3000/session',
            method: 'delete',
          },
          user: {
            url: '/users/me',
            method: 'get',
          },
        },
      },
    },
  },

this is my login test form

<script setup lang="ts">
const auth = useAuth()
const router = useRouter()

interface user {
  email: string
  password: string
}

const user: user = {
  email: '',
  password: '',
}

/**
 * If success: redirect to home page
 * Else display alert error
 */
async function login() {
  console.log(user)
  const response = await auth.login('cookie', user)
  console.log(response)
}
</script>

<template>
  <v-container>
    <form @submit.prevent="login">
      <label>E-mail</label>
      <input v-model="user.email" required type="email">
      <label>Password</label>
      <input v-model="user.password" required type="password">
      <button type="submit">
        Login
      </button>
    </form>
  </v-container>
</template>

looking in the dev console, the user object exists and the console log statement shows it just fine but you would notice right away that there is no Payload tab, so there is nothing posted to the backend:

image

and the rails backend also not showing anything:

image

i fear that this is a bug but maybe i do something wrong?

andreas-it-dev commented 1 year ago

looks like i found the issue. the data being sent must be within a body property. i dont remember this requirement from the original auth module.

would it make sense to add this to the docs?

Denoder commented 1 year ago

That addition has been in the docs for a while https://github.com/nuxt-alt/auth#changes

andreas-it-dev commented 1 year ago

oops.. thanks, i totally missed that innocent comment