Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules in Auth0 are deprecated #1015

Open
iserranoe opened this issue Dec 7, 2023 · 1 comment
Open

Rules in Auth0 are deprecated #1015

iserranoe opened this issue Dec 7, 2023 · 1 comment

Comments

@iserranoe
Copy link

iserranoe commented Dec 7, 2023

I was going through the tutorial and found myself stuck at the creation of rules in Auth0: https://hasura.io/learn/graphql/hasura/authentication/2-custom-jwt-claims-rule/

As a new tenant in Auth0, I no longer have access to Auth Pipeline and Rules, as the rules are going to be deprecated in 2024 and now we should start using Actions. https://auth0.com/docs/customize/rules/create-rules

I migrated the rules my self, I think they work fine. So, I was wondering if it would be possible to change the tutorial to use actions instead of rules.

hasura-jwt-claims

exports.onExecutePostLogin = async(event, api) => {
  const namespace = "https://hasura.io/jwt/claims";
  api.accessToken.setCustomClaim(namespace, 
    {
      'x-hasura-default-role': 'user',
      // do some custom logic to decide allowed roles
      'x-hasura-allowed-roles': ['user'],
      'x-hasura-user-id': event.user.user_id
    }
  )
};

sync-users

const request = require('request')

exports.onExecutePostLogin = async (event, api) => {
  const userId = event.user.user_id;
  const nickname = event.user.nickname;
  
  const admin_secret = "xxxx";
  const url = "xxxx";
  const query = `mutation($userId: String!, $nickname: String) {
    insert_users(objects: [{
      id: $userId, name: $nickname, last_seen: "now()"
    }], on_conflict: {constraint: users_pkey, update_columns: [last_seen, name]}
    ) {
      affected_rows
    }
  }`;

  const variables = { "userId": userId, "nickname": nickname };

  request.post({
      url: url,
      headers: {'content-type' : 'application/json', 'x-hasura-admin-secret': admin_secret},
      body: JSON.stringify({
        query: query,
        variables: variables
      })
  }, function(error, response, body){
       console.log(body);
       callback(null, user, context);
  });
}

And they need to be added to a login flow.

Thanks!

@zaq1tomo
Copy link

zaq1tomo commented Apr 8, 2024

I encountered the same issue. Considering that this tutorial at https://hasura.io/learn/ is the most accessible content for visitors, I believe there is a high likelihood of this issue recurring in the future. Are there any plans to revise the tutorial? Please let me know if there is anything I can do to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants