I’m currently implementing this:
But where do you put environment variables in Auth0 for actions?
I’m currently implementing this:
But where do you put environment variables in Auth0 for actions?
Hi @stoplion,
Thanks for reaching out to the Auth0 Community!
You can set environment variables as Secrets in Actions.
Please see our Write Your First Action documentation to learn more.
May I help you with anything else?
Thanks,
Rueben
Hi @stoplion,
Attaching the code snippet below:
const { MongoClient } = require("mongodb");
exports.onExecutePostUserRegistration = async (event) => {
const newUser = { sub: event.user.sub };
const client = await MongoClient.connect(event.secrets.MONGO_DB);
const db = client.db();
await db.collection("users").insertOne(newUser);
client.close();
};
The URL value of the event.secrets.MONGO_DB
should be your MongoDB URL, which should be in the format:
mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]
For example:
mongodb://mongodb0.example.com:27017
Reference: https://www.mongodb.com/docs/manual/reference/connection-string/
I hope this helps!
Please let me know if I can do anything else to help.
Thanks,
Rueben
Thanks. One last thing. I’m using MongoDB Cloud, and it requires I whitelist urls. Currently the action isn’t working (not saving a user). My guess is that I need to whitelist Auth0? Is there a URL to the Auth0 action I can give MongoDB Cloud?
Hi @stoplion,
Yes, most definitely! You can find this information on our Auth0 IP Addresses for Allow Lists documentation.
Please feel free to reach out again if you have any more questions.
Thanks,
Rueben
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
Hey team!
Since this topic touches Auth0 Actions, quick heads-up that we’re hosting an Ask Me Anything dedicated to Actions with Gaston Danilo Asis Sanchez, Senior Technical Product Manager. We’ll cover practical usage, new capabilities like Transaction Metadata and Actions Types, plus a peek at what’s next.
Earn community points + a badge . If you’re exploring how Actions can streamline your auth flows, this is a great time to get direct guidance from the team.
Join the AMA & drop your questions here: August 27 Auth0 Community Ask Me Anything: Actions
Dawid