Hello,
Using the guides here:
I have created both a Rule as well as an Action to create a new user in a Postgres database hosted by Heroku everytime a user logs in through my app, which uses Auth0 and is hosted on Heroku.
The Rule and Action were built according to template, yet nothing triggers or happens to my databases when someone logs in through Auth0 on my app, nor when I login via Getting Started on the Auth0 site.
(Note that my login, via LinkedIn, is successful).
My rule:
function (user, context, callback) {
const email = user.email;
const url = “https://bright-mullet-79.hasura.app/v1/graphql”;
const upsertUserQuery =mutation($userId: String!){ insert_users(objects: [{ id: $email }], on_conflict: { constraint: users_pkey, update_columns: [] }) { affected_rows } }
;
const graphqlReq = { “query”: upsertUserQuery, “variables”: { “email”: email } };request.post({
headers: {‘content-type’ : ‘application/json’, ‘x-hasura-admin-secret’: configuration.HASURA_ADMIN_SECRET},
url: url,
body: JSON.stringify(graphqlReq)
}, function(error, response, body){
console.log(body);
callback(null, user, context);
});
}
My action:
const axios = require(“axios”);
exports.onExecutePostLogin = async (event) => {
const firstname = event.user.first_name;
const lastname = event.user.last_name;
const email = event.user.email;
const admin_secret = event.secrets.HASURA_SECRET;
const url = “https://bright-mullet-79.hasura.app/v1/graphql”;
const query = `mutation ( $email: String, $firstname: String, $lastname: String) {
insert_users(objects: { email: $email, firstname: $firstname, lastname: $lastname}, on_conflict: {constraint: users_federated_id_key}) { affected_rows } }`;
const variables = {
email: email, firstname: firstname, lastname: lastname,
};
const config = {
headers: { "content-type": "application/json", "x-hasura-admin-secret": admin_secret, },
};
const data = JSON.stringify({
query: query, variables: variables,
});
await axios.post(url, data, config);
};
Everything seems to be configured correctly, and setup according to specification… My ‘users’ database was set up with just four fields (email, first_name, last_name, picture), and only email is required.
Any suggestions on what might be the issue here?
Thanks,