Merge pull request #402 from mz8i/feature/61-forgotten-password

Introduce env variable for webapp origin
This commit is contained in:
Tom Russell 2019-08-30 13:59:38 +01:00 committed by GitHub
commit 1c1e8df704
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -72,8 +72,7 @@ async function resetPassword(req: express.Request, res: express.Response) {
if(req.body.email != undefined) {
// first stage: send reset token to email address
// this relies on the API being on the same hostname as the frontend
const { origin } = new URL(req.protocol + '://' + req.headers.host);
const origin = getWebAppOrigin();
await passwordResetService.sendPasswordResetToken(req.body.email, origin);
return res.status(202).send({ success: true });
@ -96,6 +95,14 @@ async function resetPassword(req: express.Request, res: express.Response) {
}
}
function getWebAppOrigin() : string {
const origin = process.env.WEBAPP_ORIGIN;
if (origin == undefined) {
throw new Error('WEBAPP_ORIGIN not defined');
}
return origin;
}
export default {
createUser,
getCurrentUser,

View File

@ -25,6 +25,7 @@ module.exports = {
MAIL_SERVER_PORT: 587,
MAIL_SERVER_USER: "mail_username",
MAIL_SERVER_PASSWORD: "longrandompassword",
WEBAPP_ORIGIN: "http://localhost:3000",
}
}
]

View File

@ -22,6 +22,7 @@ module.exports = {
MAIL_SERVER_PORT: 587,
MAIL_SERVER_USER: "mail_username",
MAIL_SERVER_PASSWORD: "longrandompassword",
WEBAPP_ORIGIN: "https://beta.colouring.london",
}
}
]