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