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

Lost params on user creation using strapi-plugin-passwordless #9

Closed
gundall opened this issue Sep 7, 2022 · 2 comments
Closed

Lost params on user creation using strapi-plugin-passwordless #9

gundall opened this issue Sep 7, 2022 · 2 comments

Comments

@gundall
Copy link

gundall commented Sep 7, 2022

Hi! I noticed that if you use the plugin's /api/passwordless/send-link endpoint with non-existing user data, it will create a new user with that data. I'm taking advantage of this feature in my project's registration view, but I need to add an avatar as an additional parameter:

import axios from "axios";

// Stuff...

axios
    .post(`${BASE_URL}api/passwordless/send-link`, {
        ...{
	    avatar: "1",
	    email: "john@doe.com",
	    username: "JohnnyDoe21"
        },
        ...{
            headers: {
                cors: "*"
            }
        }
    })

The problem is that when I send the data to the endpoint (avatar, username, and email), the "avatar" field is ignored by the plugin. If I check the users-permissions's beforeCreate life cycle method, the "params" field doesn't contain "avatar"; it is removed:

{
  action: 'beforeCreate',
  model: { ... },
    lifecycles: {},
    indexes: [ [Object], [Object] ],
    columnToAttribute: { ... }
  },
  state: {},
  params: {
    data: {
      email: 'john@doe.com',
      username: 'JohnnyDoe21',
      role: [Object],
      createdAt: 2022-09-07T10:59:29.049Z,
      updatedAt: 2022-09-07T10:59:29.049Z
    },
    populate: [ 'role' ]
  }
}

Is there a way to make the plugin to keep certain params if required?

Thank you in advance!

@gundall
Copy link
Author

gundall commented Sep 7, 2022

I have found a working solution for this, and commited it into my forked version of this repository. I'll create a pull request in order to let you decide if it is worthwhile, or not.

This solution works this way: if you need more params (e.g. "avatar"), there are two things to do:

  1. Add that param to the data object.
  2. Add an additional param called "keepParams". This param has to be a list (array) of the param names you want the plugin to keep in the user creation; in this case, it will be ["avatar"].

This is how it would look in the previous example:

import axios from "axios";

// Stuff...

axios
    .post(`${BASE_URL}api/passwordless/send-link`, {
        ...{
	    avatar: "1",
	    email: "john@doe.com",
	    username: "JohnnyDoe21",
            keepParams: ["avatar"]
        },
        ...{
            headers: {
                cors: "*"
            }
        }
    })

gundall pushed a commit to gundall/strapi-plugin-passwordless that referenced this issue Sep 7, 2022
@tadinski
Copy link

tadinski commented Oct 3, 2022

@gundall thanks for the solution, works well.

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

No branches or pull requests

3 participants