Question:: Can we use “localhost” in Auth0 Actions?
I use Auth0 for Authentication for SPA(Next.js and Rails API)
Like this:
I want to sync auth0’s “user_id” with our MySQL Database, when a user sign up.
To achieve this, I thought Auth0 Actions’s “post registrations” looked good.
And I found good example in “Post User Registration documentation”. (Post User Registration Flow)
I tried this example, my new actions. like this.
const axios = require("axios");
exports.onExecutePostUserRegistration = async (event) => {
const { user: { email, user_id } } = event
try {
await axios.post("http://localhost:9292/api/v1/users", { params: { email, user_id }});
} catch (error) {
console.error(error)
}
};
But, this code was not working. I got a error message.
Error { Error: connect ECONNREFUSED 127.0.0.1:9292
at TCPConnectWrap.afterConnect [as oncomplete]
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 9292,
I’m guessing this is because localhost means the server where Actions is running, I ran the sample code by exposing my localhost using ngrok (https://ngrok.com/).
0d2du0602266.ngrok.io → localhost:9292
const axios = require("axios");
exports.onExecutePostUserRegistration = async (event) => {
const { user: { email, user_id } } = event
try {
await axios.post("http://0d2du0602266.ngrok.io/api/v1/users", { params: { email, user_id }});
} catch (error) {
console.error(error)
}
};
This code is working, and User Data is inserted our MySQL Database.
But, this solution isn’t good. Because we have to keep ngrok running during development, and the endpoint URL will change for each member of the team.
Is there a way to use the localhost endpoint in Auth0 Actions, or is there a non-Actions option to synchronize Auth0 user data?