Open
Description
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!
Metadata
Metadata
Assignees
Labels
No labels