I created a confirm email request after signing up. The link sent to the email directs the user to a localhost:3000 which is my API base URL, how can I send it to a localhost:8000 and still have the token working on ionic? Any help is appreciated. Thanks in advance!
//SignUpCode && SendsEmailForVerification
app.post('/insertuser', function (_req, res) {
var data = JSON.parse(_req.body.data);
var username = data.username;
var password = data.password;
var email = data.email;
var date = new Date();
var mail = {
username: username,
email: email,
created: date.toString()
}
secret_code = sha1(pnumber) //since pnumber is unique;
const token_mail_verification = jwt.sign(mail, secret_code, { expiresIn: '1d' });
var url = "http://localhost:3000/verify?username=" + token_mail_verification;
mysqlConnection.connect(function () {
var query = "Insert into Customer (Username,Email,Password) values('" + username + "','" + email + "','" + sha1(password) + "')";
mysqlConnection.query(query, function (err, results, _fields) {
if (err) {
console.log(err);
res.send('Please try again!');
}
else {
if (results.affectedRows > 0) {
var mailOptions = {
from: 'myemail',
to: email,
subject: "Account Verification",
text: "Click on the link below to veriy your account " + url,
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
//Handle error here
res.send('Please try again!');
} else {
console.log('Email sent: ' + info.response);
res.send('Thanks for registering! Please confirm your email! We have sent a link!');
}
});
}
else {
console.log("Try again");
res.send('Please try again!');
}
}
})
})
});
//CodeToVerifyEmail
app.get('/verify', function (req, res) {
token = req.query.username;
if (token) {
try {
jwt.verify(token, secret_code, (e, decoded) => {
if (e) {
console.log(e)
return res.sendStatus(403)
} else {
var email = decoded.email;
mysqlConnection.connect(function () {
var query =
"UPDATE Customer SET Subscription = 'True' WHERE Email = '" + email + "'";
mysqlConnection.query(query, function (err, results, _fields) {
if (err) {
console.log(err);
res.send('Please try again!');
}
else{
res.send('Email Verified Successfully! Please Login now! ');
}
});
});
}
});
} catch (err) {
console.log(err)
return res.sendStatus(403)
}
} else {
return res.sendStatus(403)
}
});