Hi! I’ve been trying to set up an action to call my api after user registration, the trigger is post-user-registration but it’s just not being called, I set up another action before with the login trigger and it works perfectly in that case, for the user registration I followed these steps
Created custom action
Added packages
Deployed action
Added action to flow
Created a user
Checked logs everywhere
It’s a small piece of code so it was easy to check everything was right, but I’m not getting any logs so I don’t know what’s going on, it’s just not being called so I might try with a hook later if it doesn’t work
Ps: I should mention I tested it like 30 times at least and it just kept triggering the login action instead. I tried debuggind with the test tool and it gives me a result so I know my api is working
Thank you in advance for checking this!! lmk if you need more information
Hi @nicolascalev !
What type of connection are you using for this? Just to clarify, Post User Registration is for Database and Passwordless connections, not for external identity providers (like social or enterprise connections).
What is your tenant and region?
I tested with Database connection a couple times, but now it makes sense that signing up with social connection wasn’t triggering the action. I’m curious about why the database one wasn’t triggering it either tho. Is there an alternative that could be triggered post user signup (either db or social connection), with rules, hooks or actions? if not it’s okay if there’s a workaround to do this
My tenant is dev-nicolascalev and region US-3
Also to give you more background, I’m trying to save the auth 0 user id and some extra info in my database after user sign up
The database user signup should trigger the post user registration every time a new user signs up. Can you still reproduce this issue?
As for external providers “sign up”, a nice and reliable trick is to check for a metadata flag and, if not present, do whatever you want to do on the first login and then write the flag, so that the action is only executed once.
Something like this:
async function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
if (!user.app_metadata.signupProcessed) {
await [...] // do something for a user first login
user.app_metadata.signupProcessed = true;
try {
await auth0.users.updateAppMetadata(user.user_id, user.app_metadata);
callback(null, user, context);
} catch (err) {
callback(err);
});
} else {
callback(null, user, context);
}
}
Now, a rule like this will also execute the logic for all previously existing users, so if you don’t want that you might want to add additional restrictions, like “if no flag present and user was created after x date”.
Yes I was still able to reproduce this issue I did it a couple times, in the screen shot you can confirm that only the login action was triggered, but it’s okay because I liked that workaround!!!
In the other hand, that workaround worked perfectly! I’ll stick to that giveen that it works with social login too, thanks a lot🙌🏽
I’m sharing the code I used in a post-login action, since it uses the api object to update user app metadata, might help someone
const axios = require('axios')
exports.onExecutePostLogin = async (event, api) => {
// if user has app_metadata and signupProcessed = true, then we don't need to create the user
if (event.user.app_metadata && event.user.app_metadata.signupProcessed) {
console.log('User sign up has been processed already')
return
}
try {
// query app api to store user info
const { data } = await axios.post('https://yourapi.test/api/user', {
auth0UserId: event.user.user_id,
email: event.user.email,
name: event.user.name,
picture: event.user.picture
})
console.log('User created', data)
// if everything went well then update signupProcessed to true
api.user.setAppMetadata('signupProcessed', true)
} catch (err) {
console.error(err)
}
};
Thanks you so much, Nicolas. This was really helpful for me. I really appreciate it when people who figure out how to do something also share their solution.
Hey @stany! Just a quick heads up that I have raised this issue with engineering internally and am happy to provide an update as soon as I have more information myself.
I’ve already checked with your support team on this, the actual Post User Registration trigger is firing, the bug here is that logs are not showing up as part of Action Details, but I was able to see the logs using Real-time Webtask Logs Extension