Skip to content

Commit

Permalink
Refactor: use isSecure
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs committed Mar 23, 2023
1 parent 0134f96 commit aefef7b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/routes/v1/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { config } from "@config/config"

import { isSecure } from "@root/utils/auth-utils"

const axios = require("axios")
const express = require("express")
const queryString = require("query-string")
Expand Down Expand Up @@ -28,7 +30,6 @@ const CLIENT_SECRET = config.get("github.clientSecret")
const REDIRECT_URI = config.get("github.redirectUri")
const CSRF_TOKEN_EXPIRY_MS = 600000
const FRONTEND_URL = config.get("app.frontendUrl")
const NODE_ENV = config.get("env")

const CSRF_COOKIE_NAME = "isomer-csrf"
const COOKIE_NAME = "isomercms"
Expand All @@ -52,7 +53,7 @@ async function authRedirect(req, res) {
const cookieSettings = {
expires: csrfTokenExpiry,
httpOnly: true,
secure: NODE_ENV !== "dev" && NODE_ENV !== "staging" && NODE_ENV !== "test",
secure: isSecure,
}

const token = jwtUtils.signToken({ state })
Expand Down
4 changes: 1 addition & 3 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import CollaboratorsService from "./services/identity/CollaboratorsService"
import LaunchClient from "./services/identity/LaunchClient"
import LaunchesService from "./services/identity/LaunchesService"
import { rateLimiter } from "./services/utilServices/RateLimiter"
import { isSecure } from "./utils/auth-utils"

const path = require("path")

Expand Down Expand Up @@ -88,11 +89,8 @@ const express = require("express")
const helmet = require("helmet")
const createError = require("http-errors")

const NODE_ENV = config.get("env")
const SESSION_SECRET = config.get("auth.sessionSecret")

const isSecure = NODE_ENV !== "dev" && NODE_ENV !== "test"

const SequelizeStore = SequelizeStoreFactory(session.Store)
const sessionMiddleware = session({
store: new SequelizeStore({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/auth-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { config } = require("@config/config")
const NODE_ENV = config.get("env")

function isSecure() {
return NODE_ENV !== "dev" && NODE_ENV !== "staging" && NODE_ENV !== "test"
return NODE_ENV !== "dev" && NODE_ENV !== "test"
}

module.exports = {
Expand Down

0 comments on commit aefef7b

Please sign in to comment.