Skip to content

Cleanup password field if it's not set #2

@BDav24

Description

@BDav24

When I click on "Change password", then "Cancel", the password param is sent with an empty value, which gives the error: no such column: password

I suggest changing encryptPassword function to:

const encryptPassword: Before = async (request) => {
  const { method } = request
  const { [passwordProperty]: newPassword, ...rest } = request.payload || {}

  if (method === 'post') {
    return {
      ...request,
      payload: {
        ...rest,
        ...(newPassword ? { [encryptedPasswordProperty]: await hash(newPassword) } : null)
      },
    }
  }
  return request
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions