diff --git a/backend/.env b/backend/.env index b2f01e3406153054bfcc7c1e0220cd0bb718f0c2..ce7e7979ff8246c8edc80fa269254ae8e6c597e8 100644 --- a/backend/.env +++ b/backend/.env @@ -5,4 +5,4 @@ DB_PASSWORD=corps_db_password DB_NAME=corps_directory_db PORT=3000 -FRONTEND_URL=localhost:8080 \ No newline at end of file +FRONTEND_URL=http://localhost:8080 \ No newline at end of file diff --git a/backend/config/auth/auth.login.js b/backend/config/auth/auth.login.js index 022d88258ae198edfff4d580387041738acf2626..ebf5d6eaba54608c32e4e9c7706f429d03c832e0 100644 --- a/backend/config/auth/auth.login.js +++ b/backend/config/auth/auth.login.js @@ -9,6 +9,28 @@ const casLogin = function (req, res, next) { // hard-coded for now. const JWT_SECRET = "secret_key"; + // if on localhost, accept the authentication and give a key + console.log("user: ", process.env.DB_USER); + + if (process.env.DB_USER === "corps_directory_dev") { + // payload for the JWT token + const payload = { + id: 1, + role: "admin", + username: "localhostuser", + }; + + // sign the token with secret key + const token = jwt.sign(payload, JWT_SECRET, { expiresIn: "1h" }); + + console.log("sending token for use in localhost"); + + console.log("Frontend: ", process.env.FRONTEND_URL); + + res.redirect(`${process.env.FRONTEND_URL}/home?token=${token}`); + return; + } + // call the authenticate function with CAS passport.authenticate("cas", function (err, user, info) { if (err) {