I'm using the Mailgun node machine-pack to send an email with a url that has a JWT created using machinepack-jwt in it. When the user clicks "confirm" in the generated email it hits my Sails controller method where I want to decode the JWT.
I keep getting an object with properties that have empty strings as their value.
For reference: I'm using node-machine machinepack-jwt to do the encoding and decoding. I tried to tag the question as such but this tag isn't in the available tags and I don't have the required 1500 rep points
My sails controller:
module.exports = {
//Encode method
signup: function (req, res){
if (!req.param('serviceManager')) {
res.badRequest('Missing required parameter!');
} else {
var Mailgun = require('machinepack-mailgun');
var JWT = require('machinepack-jwt');
var newUser = req.param('serviceManager');
JWT.encode({
secret: 'my_secret',
algorithm: 'my_algo',
expires: 2880, //in minutes(two days)
payload: newUser.email + ':' + newUser.password
}).exec({
error: function (err){
console.log(err);
},
success : function (authToken){
Mailgun.sendHtmlEmail({//my Mailgun send with template that has authToken in it});
//Decode method
confirm_email: function (req, res){
if (!req.params[0]) {
res.badRequest('Missing required parameter!');
} else {
var JWT = require('machinepack-jwt');
var authToken = req.params[0];
console.log(authToken);
JWT.decode({
secret: 'my_secret',
token: authToken,
algorithm: 'my_algo'
}).exec({
error: function (err) {
res.send(err);
},
success: function (decodedToken) {
res.view('emailconfirmed');
console.log(decodedToken);// returns { id: '', email: '', role: '', sessionId: '' }
}
});
}
}
What I'm expecting is the users email and password which I've encoded in the sent JWT.