Hi, I’m trying to migrate from rules to actions. The guide was pretty great and I think i’ve got everything good to go. However my idToken is not being set anymore.
Here is the rule I was using:
function(user, context, callback) {
const fetch = require('node-fetch');
// call our login lambda
fetch('https://mydomain/i/login', {
method: 'POST',
headers: { authorization: configuration.MYTOKEN },
body: JSON.stringify({ user }),
timeout: 15000
})
.then(res => {
if (!res.ok) {
res.json().then((errorData) => {
// non 2xx status code
console.log('ERROR', errorData);
return callback(new Error(errorData));
});
}
res.json().then((data) => {
const { smplrspace, hasura } = data;
// add custom data
const smplrNamespace = "https://smplrspace.com/jwt/claims";
context.idToken[smplrNamespace] = smplrspace;
// add hasura token
const hasuraNamespace = "https://hasura.io/jwt/claims";
context.accessToken[hasuraNamespace] = hasura;
// finish
console.log(`Login: ${user.name} (${user.email})`);
callback(null, user, context);
});
})
.catch(error => {
console.log('ERROR', error);
return callback(new Error(error));
});
}
and here is the action code:
const fetch = require('node-fetch') // version 2.6.1
exports.onExecutePostLogin = async (event, api) => {
// call our login lambda
fetch('https://mydomain/i/login', {
method: 'POST',
headers: { authorization: event.secrets.MYTOKEN },
body: JSON.stringify({ user: event.user }),
timeout: 15000,
})
.then((res) => {
if (!res.ok) {
res.json().then((error) => {
// non 2xx status code
console.log('ERROR', error)
return api.access.deny(error.message)
})
}
res.json().then((data) => {
const { smplrspace, hasura } = data
// add custom data
const smplrNamespace = 'https://smplrspace.com/jwt/claims'
api.idToken.setCustomClaim(smplrNamespace, smplrspace)
// add hasura token
const hasuraNamespace = 'https://hasura.io/jwt/claims'
api.accessToken.setCustomClaim(hasuraNamespace, hasura)
// finish
console.log(`Login: ${event.user.name} (${event.user.email})`)
return
})
})
.catch((error) => {
console.log('ERROR', error)
return api.access.deny(error.message)
})
}
The idToken appears unmodified in my frontend code (no changes there). Any idea?
Thanks in advance