From a9bd8fe5f6ab533647c20bdc9b34cad435e4a443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaarel=20=C3=95un?= Date: Tue, 15 Feb 2022 12:42:31 +0200 Subject: [PATCH] use https --- server/controllers/AuthController.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/server/controllers/AuthController.js b/server/controllers/AuthController.js index c43c434..fa36e11 100644 --- a/server/controllers/AuthController.js +++ b/server/controllers/AuthController.js @@ -3,21 +3,17 @@ import { knex } from '../database' export default class AuthController { async oAuthCallback(req, res) { + const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http' + const port = process.env.NODE_ENV === 'production' ? '' : ':3000' + const baseUrl = `${protocol}://${req.hostname}${port}` + try { await Auth.authorizeVehicle(req) - res.redirect( - `http://${req.hostname}${ - req.hostname === 'localhost' ? ':3000' : '' - }/dashboard` - ) + res.redirect(`${baseUrl}/dashboard`) } catch (err) { console.log(err) - res.redirect( - `http://${req.hostname}${ - req.hostname === 'localhost' ? ':3000' : '' - }/connect?error=${err.message}` - ) + res.redirect(`${baseUrl}/connect?error=${err.message}`) } }