I want to have the users to verify their emails before the user can actually log in. I added the following to the post login action to redirect them to a page on my app.
exports.onExecutePostLogin = async (event, api) => {
if (!event.user.email_verified) {
// Craft a signed session token
const token = api.redirect.encodeToken({
secret: event.secrets.MY_REDIRECT_SECRET,
expiresInSeconds: 60,
payload: {
continue_uri: `https://${YOUR_AUTH0_DOMAIN}/continue`
},
});
api.redirect.sendUserTo("http://localhost:4200/verify", {
query: { session_token: token }
});
}
}
After they are redirected to my Angular page, they will see this a button, and after they click it will call the api to trigger resend verification email
ngOnInit() {
this.activatedRoute.queryParamMap.subscribe(params => {
if (params.get('session_token')) {
this.userId = this.getDecodedAccessToken(params.get('session_token')).sub;
}
});
}
private getDecodedAccessToken(token: any):any {
try {
const obj = jwt_decode(token);
console.log(obj);
return obj;
}
catch(Error) {
return null;
}
}
resendEmailVerification() {
this.managementService.resendVerificationEmail({user_id: this.userId}).subscribe({
next: (result) => {
console.log(result);
}
})
}
I was able to get the userId and parse the session token successfully, but when the api is called, it get the following error:
Any idea why this is happening?