fix: default jwt role

This commit is contained in:
devthejo 2026-01-11 15:07:59 +01:00
parent fc0733998e
commit e64ecfd023
No known key found for this signature in database
GPG key ID: 00CCA7A92B1D5351
2 changed files with 1 additions and 13 deletions

View file

@ -1,10 +0,0 @@
module.exports = function () {
const rolesByLevel = {
admin: 1,
user: 100,
}
return function sortRolesByLevel(roles) {
return roles.sort((a, b) => rolesByLevel[a] - rolesByLevel[b])
}
}

View file

@ -142,10 +142,8 @@ module.exports = ({ services }) => {
} }
async function generateUserJwt(userId, deviceId, roles) { async function generateUserJwt(userId, deviceId, roles) {
const [defaultRole] = services.sortRolesByLevel(roles)
const hasuraClaim = {} const hasuraClaim = {}
hasuraClaim["x-hasura-default-role"] = defaultRole hasuraClaim["x-hasura-default-role"] = "user"
hasuraClaim["x-hasura-allowed-roles"] = roles hasuraClaim["x-hasura-allowed-roles"] = roles
hasuraClaim["x-hasura-user-id"] = userId.toString() hasuraClaim["x-hasura-user-id"] = userId.toString()
hasuraClaim["x-hasura-device-id"] = deviceId.toString() hasuraClaim["x-hasura-device-id"] = deviceId.toString()