Denoder / nuxt-module-alternatives

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

auth module, FetchError: Failed to execute 'fetch' on 'Window': Invalid value () #130

Closed Opyd closed 1 year ago

Opyd commented 1 year ago

While trying to log with strategy: FetchError: Failed to execute 'fetch' on 'Window': Invalid value () What I'm missing?

nuxt.config.ts:

export default defineNuxtConfig({
    ssr: false,
    modules : [
        '@nuxtjs-alt/auth',
        '@nuxtjs-alt/http',
        '@pinia/nuxt'
    ],
    http: {
        baseURL: 'http://127.0.0.1:3100/api'
    },

    auth: {
        strategies: {
            local: {
                token: {
                    property: 'accessToken',
                    global: true,
                },
                user: {
                    property: 'user',
                },
                endpoints: {
                    login: { url: '/api/auth/login', method: 'post' },
                    logout: { url: '/api/auth/logout', method: 'post' },
                    user: { url: '/api/auth/user', method: 'get' }
                }
            }
        }
    }
})

Click.vue:

<template>
 <button @click="click">Click</button>
</template>

<script setup lang="ts">

const {$auth} = useNuxtApp();

async function click(){
  try {
    const res = await $auth.loginWith('local', {
      body: {
        username: 'test',
        password: 'test'
      }

    })
  } catch (e){
    console.log(e)
  }
}

</script>

<style scoped>

</style>
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.