I’m trying to send an email after user registration to validate the email, but I keep getting the error:
No user pre-authenticated, cannot send code
<service verb="signup" noun="User" authenticate="anonymous-all">
<implements .../>
<actions>
<script><![CDATA[
//... existing code
ec.web?.sessionAttributes.put("moquiPreAuthcUsername", username)
ec.web?.sessionAttributes?.put("moquiAuthcFactorRequired", "true")
def factorId = ec.service.sync()
.name('org.moqui.impl.UserServices.create#UserAuthcFactorEmail')
.parameters([
userId: userId,
factorOption: emailAddress
])
.call()
.factorId
ec.service.async()
.name('org.moqui.impl.UserServices.send#ExternalAuthcCode')
.parameters([
factorId: factorId
]).call()
To solve this, I tried adding moquiPreAuthcUsername, but I still get the same error. I noticed that this value doesn’t update globally.
Note that I used LoginAfterCreate: False while creating user.
<service-call name="mantle.party.PartyServices.create#Account"
in-map="context + [loginAfterCreate: false]" out-map="result"/>
What’s the proper solution for pre-authentication in this case? Or is there an alternative way to send verification codes and validate them without requiring pre-auth?