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

Wiki page should tell about processors can be return with Promise. #4

Open
nakorndev opened this issue Dec 6, 2019 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@nakorndev
Copy link

Sorry for my English. But the document is lack about using asynchronous programming.

So, I was tried with below code

processors: {
    async password (value) {
        const hashed = await bcrypt.hashSync(value, Number(process.env.SALT_ROUND))
        return hashed
    }
}

In database will not set any data as hashed resolve on await statement. But instead it's work with return promise then processors will resolve itself.

processors: {
    password (value) {
        return bcrypt.hashSync(value, Number(process.env.SALT_ROUND))
    }
}

Thanks.

@scottmangiapane
Copy link

I'm seeing the same issue as @nakorndev. It looks like whenever the processor is an async function, it is called an extra time with a value of '{}', which causes junk data to be stored in the DB. I tested this using a function similar to:

processors: {
  password: async (value) => {
    console.log(value + ' is a ' + (typeof value)); // {} is a string
    return value;
  }
}

If I remove "async" and try again I do not see this issue.

@ricardograca
Copy link
Member

This plugin wasn't designed with async processors in mind. I'll mark this as a feature request.

@ricardograca ricardograca added the enhancement New feature or request label Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants