Denoder / nuxt-module-alternatives

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

loginWith('local', { body: userPrincipal }). #131

Closed steklopod closed 1 year ago

steklopod commented 1 year ago

Environment

 "dependencies": {
    "@nuxtjs-alt/auth": "2.1.6",
    "@nuxtjs-alt/axios": "^1.1.0",
    "@nuxtjs-alt/http": "^1.5.3",
    "@nuxtjs-alt/proxy": "^2.1.0",
    "@pinia/nuxt": "0.4.3",
    "js-cookie": "3.0.1",
    "pinia": "2.0.23",
    "sass": "1.56.1",
    "vuetify": "^3.0.1"
  },
  "devDependencies": {
    "nuxt": "3.0.0"
  }

Nuxt Config


import { defineNuxtConfig } from 'nuxt/config'

const host = 'https://colaba.online';

export default defineNuxtConfig({
  ssr: true,
  runtimeConfig: {
    public: {
      API_URL: `${host}/api`
    }
  },
  build: {
    transpile: ['vuetify']
  },
  css: ['vuetify/lib/styles/main.sass'],
  modules: ['@pinia/nuxt',
            '@nuxtjs-alt/auth',
            '@nuxtjs-alt/http',
            '@nuxtjs-alt/proxy', // needed if using ssr
            '@pinia/nuxt'],
  auth: {
    scopeKey: 'scope',
    globalMiddleware: true,
    // fullPathRedirect: false,
    strategies: {
      local: {
        scheme: 'refresh',
        user: { property: false },
        token: {
          property: 'access_token',
          required: true,
          type: 'Bearer',
          maxAge: 60 * 2
        },
        refreshToken: {
          property: 'refresh_token',
          tokenRequired: false,
          maxAge: 60 * 60 * 24 * 21
        },
        endpoints: {
          login: { url: `${host}/api/auth/login`, method: 'post' },
          user: { url: `${host}/api/auth/user`, method: 'post' }
        }
      }
    }
  },
})

Reproduction

https://stackblitz.com/edit/nuxt-starter-ykgz8i?file=pages%2Flogin%2Findex.vue,nuxt.config.ts,package.json

You can test it from localhost:3000 also.

Existing in backend user already provided. Just press login button.

Describe the bug

Can't login with strategy local

Additional context

No response

Logs

request-handler.mjs?v=55d9fab5:15 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'setHeader')
    at RequestHandler.clearHeader (request-handler.mjs?v=55d9fab5:15:17)
    at Token.reset (token.mjs?v=55d9fab5:31:32)
    at RefreshScheme.reset (refresh.mjs?v=55d9fab5:119:16)
    at Auth.reset (auth.mjs?v=55d9fab5:156:1)
    at RefreshScheme.login (local.mjs?v=55d9fab5:80:18)
    at Auth.login (auth.mjs?v=55d9fab5:110:1)
    at auth.mjs?v=55d9fab5:104:1
    at async login (index.vue:16:3)