Skip to content

Commit

Permalink
fix(env): set default credentials when .env is not set (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr authored Sep 28, 2023
1 parent 390e646 commit f545433
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
8 changes: 3 additions & 5 deletions targets/frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ export const ACCOUNT_MAIL_SENDER = "[email protected]";
export const JWT_TOKEN_EXPIRES = 15; // 15 min
export const REFRESH_TOKEN_EXPIRES = 43200; // 30 days in minutes
export const ACTIVATION_TOKEN_EXPIRES = 10080; // 7 days in minutes
export const HASURA_GRAPHQL_JWT_SECRET = process.env
.HASURA_GRAPHQL_JWT_SECRET ?? {
type: "HS256",
key: "a_pretty_long_secret_key_that_should_be_at_least_32_char",
};
export const HASURA_GRAPHQL_JWT_SECRET =
process.env.HASURA_GRAPHQL_JWT_SECRET ??
'{"type":"HS256","key":"a_pretty_long_secret_key_that_should_be_at_least_32_char"}';
export const BASE_URL = process.env.FRONTEND_HOST || `http://localhost:3000`;
4 changes: 2 additions & 2 deletions targets/frontend/src/lib/azure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
} from "@azure/storage-blob";

const AZURE_STORAGE_ACCOUNT = {
key: process.env.AZURE_STORAGE_ACCOUNT_KEY || "",
name: process.env.AZURE_STORAGE_ACCOUNT_NAME || "",
key: process.env.AZURE_STORAGE_ACCOUNT_KEY || "accountKey",
name: process.env.AZURE_STORAGE_ACCOUNT_NAME || "cdtnadmindev",
};

export const getBlobContainer = (containerName) => {
Expand Down
6 changes: 3 additions & 3 deletions targets/frontend/src/lib/emails/sendmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import nodemailer from "nodemailer";
export default function sendmail(mailOptions) {
const transport = nodemailer.createTransport({
auth: {
pass: process.env.SMTP_EMAIL_PASSWORD,
user: process.env.SMTP_EMAIL_USER,
pass: process.env.SMTP_EMAIL_PASSWORD ?? "pass",
user: process.env.SMTP_EMAIL_USER ?? "email",
},
host: process.env.SMTP_URL,
host: process.env.SMTP_URL ?? "smtp.url",
port: 587,
});
return transport.sendMail(mailOptions).finally(() => transport.close());
Expand Down
4 changes: 1 addition & 3 deletions targets/frontend/src/pages/api/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { getExpiryDate } from "src/lib/duration";

import { loginQuery, refreshTokenMutation } from "./login.gql";

const { REFRESH_TOKEN_EXPIRES = "" } = process.env;

import { JWT_TOKEN_EXPIRES } from "../../config";
import { JWT_TOKEN_EXPIRES, REFRESH_TOKEN_EXPIRES } from "../../config";

export default async function login(req, res) {
const apiError = createErrorFor(res);
Expand Down
2 changes: 1 addition & 1 deletion targets/frontend/src/pages/api/storage/[path].js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createErrorFor } from "src/lib/apiError";
import { deleteBlob } from "src/lib/azure";
import { HASURA_GRAPHQL_JWT_SECRET } from "../../../config";

const container = process.env.STORAGE_CONTAINER;
const container = process.env.STORAGE_CONTAINER ?? "cdtn-dev";
const jwtSecret = JSON.parse(HASURA_GRAPHQL_JWT_SECRET);

export default async function deleteFiles(req, res) {
Expand Down
2 changes: 1 addition & 1 deletion targets/frontend/src/pages/api/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isUploadFileSafe } from "src/lib/secu";
import * as stream from "stream";
import { HASURA_GRAPHQL_JWT_SECRET } from "../../../config";

const container = process.env.STORAGE_CONTAINER;
const container = process.env.STORAGE_CONTAINER ?? "cdtn-dev";
const jwtSecret = JSON.parse(HASURA_GRAPHQL_JWT_SECRET);

async function endPoint(req, res) {
Expand Down

0 comments on commit f545433

Please sign in to comment.