Skip to content

Error "Cannot create property 'client_id' on string" with scheme refresh and x-www-form-urlencoded #977

Closed
@existe-deja

Description

@existe-deja

Version

module: 5.0.0-1608568767.2fe2217
nuxt: 2.14.12

Nuxt configuration

mode:

  • universal
  • spa

Nuxt configuration

auth: {
    redirect: {
      login: '/login',
      logout: '/',
      callback: '/dashboard',
      home: '/dashboard'
    },
    strategies: {
      local: {
        scheme: 'refresh',
        token: {
          property: 'access_token',
          required: true,
          type: 'Bearer',
          name: 'Authorization',
          maxAge: 60 * 30
        },
        refreshToken: {
          property: 'refresh_token',
          data: 'refresh_token',
          maxAge: 60 * 30
        },
        user: {
          property: false,
          autoFetch: true
        },
        clientId: process.env.API_KEY,
        endpoints: {
          login: {
            url: '/oauth/token/',
            method: 'post',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
          },
          logout: false,
          user: {
            url: '/users/me/',
            method: 'get'
          }
        }
      }
    }
  }

Reproduction

const formLogin = Object.keys(this.login)
  .map(a => encodeURIComponent(a) + '=' + encodeURIComponent(this.login[a]))
  .join('&')

 try {
  await this.$auth.loginWith('local', { data: formLogin })
} catch (e) {
  console.error(e)
}

What is expected?

I expect clientId from config to be injected in the request data.

What is actually happening?

Because my ata is strongofied, auth module cannot inject my clientId inside the request data.
TypeError: Cannot create property 'client_id' on string 'username=aaa&password=bbb'

if (this.options.clientId) {
  endpoint.data.client_id = this.options.clientId;
}

Steps to reproduce

Try to login with a stringified data.

Additional information

Checklist

  • I have tested with the latest Nuxt version and the issue still occurs
  • I have tested with the latest module version and the issue still occurs
  • I have searched the issue tracker and this issue hasn't been reported yet

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions