Manipulating User on BeforeSave breaks email verification

Hey guys,

I am struggling at the moment.

Parse.Cloud.beforeSave("_User", (request) => {
  if( request.object.get("username") ){
    request.object.set("username", request.object.get("username").toLowerCase())
    request.object.set("email", request.object.get("username") );

    console.log(request.object.toJSON() );

All I want to do is to set the username to be the same as the email address automatically in the backend inside the beforeSave. But if I do that inside my Cloud Code, email verification links become invalid and are not working anymore.

Is it possible to do it this way? Any hint would be great! :slight_smile:
Best Nico

Hi Nico, welcome to the community :wave:

You said that you want to…

However, in your code you have set the email to be the username, which would probably explain why it break the email verification. If you want to set the username to equal the email address:

Parse.Cloud.beforeSave("_User", (request) => {
  if (request.object.get("username")) {
    request.object.set("username", request.object.get("email").toLowerCase())

Thanks for your answer! :slight_smile: Seems to work.

So it’s not possible to manipulate the mail adress in the before function, cause mail verification stuff will break then? Guess it should work, cause it’s BEFORE Save. :confused:

PLUS: The Rest API doesn’t accept a request for register a new User, if the username is missng… So we need to provide both (mail and username) from the frontend.

I think it should be possible but why would you want to set the email address to be the same as the username?

Can you give me an example of a username you are using?

The idea is, that the user uses his/her mail adress (and a password) to login to my app and website. To exclude this “logic” from the frontend, I assumed I can handle it the way i did originally. ( Which works)

But now I want to implement mail verification and it broke, so I guess i need to change this.

I understand what you are trying to achieve, I do this myself.

Given that you have to send the email address and the username why not just set both to the email address on the frontend?