# Post-Login Rule/Action to create a new user in Heroku / Hasura Postgresql doesn't work?

**URL:** <https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803>\
**Category:** Get Help\
**Tags:** actions, rules, heroku\
**Created:** [January 21, 2022, 1:36pm UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803 "2022-01-21T13:36:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![robliou01](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/robliou01/32/34126_2.png) [@robliou01](https://community.auth0.com/u/robliou01)\
**Post date:** [January 21, 2022, 1:36pm UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803/1 "2022-01-21T13:36:28Z")

</div>

Hello,

Using the guides here:

> **[How to Build a Collaborative To-Do App - Hasura and GraphQL Backend](https://auth0.com/blog/building-a-collaborative-todo-app-with-realtime-graphql-using-hasura/)**
>
> See how to build a real-time backend for a collaborative to-do app using Hasura and GraphQL. Application is secured using JSON Web Tokens...

> **[Syncing user data: Hasura & Auth0 for authenticated database access](https://dev.to/devgeetech/syncing-user-data-hasura-auth0-for-authenticated-database-access-5gf6)**
>
> Adding authenticated database access to your project can be a cool but tedious task. In this blog...

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](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](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,

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 21, 2022, 11:56pm UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803/3 "2022-01-21T23:56:39Z")

</div>

Hi @robliou01,

Thanks for reaching out to the Auth0 Community!

To better assist you, could you please use the [Real-time Webtask Logs Extension](https://auth0.com/docs/customize/extensions/real-time-webtask-logs) to trace the execution of your Rule/Action and share the error or success response?

While testing, you may find the built-in debugger in Actions helpful to test a sample request and see the response. With Rules, you must use the Real-time Webtask Logs extension.

Looking forward to your response.

Thanks.

---

<div class="post-metadata">

**Author:** ![robliou01](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/robliou01/32/34126_2.png) [@robliou01](https://community.auth0.com/u/robliou01)\
**Post date:** [January 22, 2022, 1:40am UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803/4 "2022-01-22T01:40:18Z")

</div>

> “While testing, you may find the built-in debugger in Actions helpful to test a sample request and see the response.”

Hi Ruben, thanks for responding.

With regards to the built-in debugger for Actions; where or how do I find this? I don’t see it anywhere on my panel… is it in the Getting Started menu?

Would it be possible to screenshot how to access this?

Thanks and Best,

---

<div class="post-metadata">

**Author:** ![robliou01](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/robliou01/32/34126_2.png) [@robliou01](https://community.auth0.com/u/robliou01)\
**Post date:** [January 22, 2022, 2:03am UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803/5 "2022-01-22T02:03:46Z")

</div>

> To better assist you, could you please use the [Real-time Webtask Logs Extension](https://auth0.com/docs/customize/extensions/real-time-webtask-logs) to trace the execution of your Rule/Action and share the error or success response?

Ruben, for testing the Rule, I’ve gone ahead and installed the Real-time Webtask Logs Extension.

As you can see, when I run the rule using Linked-in login, I get the response that my login was successful.

 ![screenshot 1](https://global.discourse-cdn.com/auth0/original/3X/c/5/c521f2fee64d24556ac1b0bed84569f14fd7e005.png)

Here is the most recent version of the Rule that I’ve been using:

> function (user, context, callback) {  
> const userId = user.user\_Id;  
> const email = user.email;  
> const url = “[https://bright-mullet-79.hasura.app/v1/graphql](https://bright-mullet-79.hasura.app/v1/graphql)”;  
> const upsertUserQuery = ` mutation($userId: String!){ insert_users(objects: [{ id: $userId, email: $email }], on_conflict: { constraint: users_pkey, update_columns: [] }) { affected_rows } }`;  
> const graphqlReq = { “query”: upsertUserQuery, “variables”: { “userId”: userId, “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);  
> });  
> }

---

<div class="post-metadata">

**Author:** ![robliou01](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/robliou01/32/34126_2.png) [@robliou01](https://community.auth0.com/u/robliou01)\
**Post date:** [January 22, 2022, 12:44pm UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803/6 "2022-01-22T12:44:52Z")

</div>

(Note that I am using sign-in with LinkedIn).

However, here is the error message that I receive in my Real-time Webtask Log:

 ![4](https://global.discourse-cdn.com/auth0/original/3X/2/4/24236711d3555c28bc568984bf3a254302aaf04c.png)

**" {“errors”:[{“extensions”:{“path”:“$”,“code”:“validation-failed”},“message”:“expecting a value for non-nullable variable: "userId"”}]}"**

I’ve gone ahead and added a ‘userId’ and “user\_id” variable to my heroku database, as well as modified the rule as above, but the same error persists.

Any idea here what is happening? Here is a screenshot of my Heroku PSQL database I created manually:

 ![5](https://global.discourse-cdn.com/auth0/original/3X/6/5/65af6c9b821bd725b29a498184b16f64bfa6c59d.png)

_I am ultimately expecting my first name, last name, email, and profile picture to be returned._

Thanks,

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 25, 2022, 5:24pm UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803/7 "2022-01-25T17:24:36Z")

</div>

Hi @robliou01,

Thank you for your responses.

> [@robliou01](#):
>
> With regards to the built-in debugger for Actions; where or how do I find this?

The Actions debugger is located on the left column with a _Play Button_. Then, clicking on the Run button below tests the Action against a sample request. See below.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/c/2/c28596774c6b4e17da79c752b95ef4351f6ce5e8.jpeg)

  

Next, after looking closely at your Real-time Webtask Logs, it appears to indicate an error about the value you passed in your request. Specifically, the value passed is null or undefined but expects a non-nullable value.

And this is consistent with the typo in your Rule. It appears that you called `user.user_Id` when the correct reference should be `user.user_id`. Could you please fix the typo and see how that works?

Please see the [User Object Properties in Rules](https://auth0.com/docs/customize/rules/user-object-in-rules) for the complete reference.

Thank you!

---

<div class="post-metadata">

**Author:** ![robliou01](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/robliou01/32/34126_2.png) [@robliou01](https://community.auth0.com/u/robliou01)\
**Post date:** [January 26, 2022, 5:46am UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803/8 "2022-01-26T05:46:01Z")

</div>

Rueben, this worked for me, thanks!

Any other questions, will be sure to let you know…

Best,

R

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 10, 2022, 5:46am UTC](https://community.auth0.com/t/post-login-rule-action-to-create-a-new-user-in-heroku-hasura-postgresql-doesnt-work/76803/9 "2022-02-10T05:46:21Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
