I found the Auth0 Management API v2 page but don’t really know how to target it, I am trying to make a rule to send a verification email to users post-login if the user email is not confirmed yet. I preferable wanted to do this in the angular code to have a button for users to request it to be sent, but couldn’t find anything to help me set it up as I don’t know how to call the api.
I am not running node with this setup.
I tried to use your reply as a guideline but still having issues.
I got this:
this.auth0Manage = new auth0.Management({
domain: AUTH_CONFIG.domain,
token: this._accessToken
});
and later the method I call:
public sendConfirmationEmail(){
var params = {
user_id: this.sessionService.getCurrentId()
};
this.auth0Manage.sendEmailVerification(params, function(err) {
if (err) {
// Handle error.
console.log(err);
}
console.log("email sent");
});
}
with this I get error “this.auth0Manage.sendEmailVerification is not a function”… If I try to use ManagementClient instead of Management, it will only return undefined - Management gives a clear connection to API v2 though.
I’m trying to set up the rule now as following, but getting failed logins with error “must specify user ID”:
function (user, context, callback) {
var ManagementClient = require('auth0@2.9.1').ManagementClient;
var management = new ManagementClient({
token: auth0.accessToken,
domain: auth0.domain
});
var params = {
user_id: '{USER_ID}'
};
management.sendEmailVerification(function (err) {
if (err) {
// Handle error.
}
});
}
In the log however, I can see I do have a ’ “user_id”: “auth0|275”, ’ associated with the user login attempt. Do I need to pull out the user id to the params, from the user in the rule/funciton param?
Thank you ! It works now Code looks like following now in the rule:
function (user, context, callback) {
var ManagementClient = require('auth0@2.9.1').ManagementClient;
var management = new ManagementClient({
token: auth0.accessToken,
domain: auth0.domain
});
var params = {
user_id: user.user_id
};
console.log("1", user);
console.log("2", params.user_id);
management.sendEmailVerification(params, function (err) {
if (err) {
// Handle error.
console.log(err);
}
console.log("email sent?");
callback(null, user, context);
});
}
Just a heads up, the example for “sendVerificationEmail” API you sent previous was missing the params in the method call - which is why it was missing in my previous post
A last question, is it possible to make a call to my Azure SQL DB when the send verification was successfully sent? Got a variable on my user I want to update in database at the same time. Edit: Found my answer to the db call stuff by going to ‘connections-> database → verify’
It works fine, but email_verified doesn’t get assigned to users post-email verify so they will always get sent a new confirmation email when they sign in, how do I proceed from here to make it work?
Glad this is working for you. I noticed the error in the doc as well, working on getting that fixed .
In regards to your most recent update- It looks like the users are getting a verification email with this rule regardless of whether or not there are verified. Typically you would want to add a conditional that performs the callback if the user is already verified.
Thank you for the quick response
I tried that already, but none of my users have that, and I do not have permissions to change user metadata either… Could this be because we are using a free account with no subscriptions? We’ve basically only been running tests so far to see if Auth0 fits our needs, and I forgot we did not subscribe for a plan yet - maybe the lack of variable on the user could be because of this?
Your subscription level shouldn’t matter for this. Go to the users tab in your dashboard, select a user, then select the ‘Raw JSON’ tab. Do you see email_verified at the top?