How to remove trunk prefix (leading zero) in phone number during SMS passwordless flow

Hey,

I’ve implemented a passwordless SMS auth flow using Lock v11 and a custom SMS gateway (Twilio integration just returned errors with or without Copilot).

It’s all working well, except that neither would Lock prevent the trunk prefix input, nor would the API remove it, so users can submit a malformed mobile number which gets passed on to our SMS gateway and users never get the OTP (or an error message) left wondering what went wrong…

What I found so far:

  1. I could remove the extra number in our SMS gateway code – this would send the message out, but the wrong phone number would be saved for the user in the Auth0 database
  2. I could remove the extra number in a Pre-User Registration Hook (see code at the bottom*) – for some reason it didn’t get triggered
  3. I could do validation with Custom Database Error Handling – but it doesn’t seem to be possible to use anything but the completely opaque sms database generated by enabling the SMS passwordless flow. Maybe that’s also the reason why 2 above didn’t work?

So far none of the options seem workable, but I’d really like to avoid having to implement a custom UI just to implement this simple validation / replace rule. Is there any option I missed or any pointers what could I do differently?

Thanks a lot in advance!

Pre-User Registration Hook code I tried (very basic, just to see if it works):

response.user = user;
response.user.phoneNumber = user.phoneNumber.replace('+440', '+44');

Hey there!

Sorry for such delay in response! We’re doing our best in providing the best developer support experience out there, but sometimes the number of incoming questions is just too big for our bandwidth. Sorry for such inconvenience!

Do you still require further assistance from us?

Hey Konrad,

I’m not working on the project any more so I personally don’t need further assistance, but this was a pretty bad issue with no proper workarounds, so I’d still recommend your team look at it if haven’t yet.

Have a nice day,
Daniel

Got it! Thank you a lot for letting us know!