Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 of 5 tasks
existe-deja opened this issue Jan 4, 2021 · 2 comments
Labels

Comments

@existe-deja
Copy link

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
@existe-deja existe-deja added the bug label Jan 4, 2021
@bmulholland
Copy link
Contributor

Per the docs, data should be an object, not a string, so this isn't a bug.

@existe-deja
Copy link
Author

Thanks for answering @bmulholland.
I rewrite my question so:
How do I handle a form-urlencoded request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants