hasura / learn-graphql

Real world GraphQL tutorials for frontend developers with deadlines!
https://hasura.io/learn/
MIT License
1.18k stars 647 forks source link

Rules in Auth0 are deprecated #1015

Open iserranoe opened 7 months ago

iserranoe commented 7 months ago

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 commented 3 months ago

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.