Skip to content

Commit

Permalink
fix: API session key to session string
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapobajza committed Sep 10, 2024
1 parent 173d367 commit 8d5a557
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "tsx watch ./src/start.ts",
"start": "tsx ./src/start.ts",
"start:prod": "tsx build.ts && node ./dist/start.js",
"start:prod": "tsx build.ts && cp session_key_prod dist/session_key && node ./dist/start.js",
"migrate": "node-pg-migrate",
"tsc": "tsc",
"test": "vitest",
Expand Down
6 changes: 1 addition & 5 deletions apps/api/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from "path";
import fs from "fs";

import {
serializerCompiler as zodSerializerCompiler,
Expand All @@ -13,7 +12,6 @@ import { type FastifyInstance } from "fastify";
import type { Pool } from "pg";
import { ZodError } from "zod";
import FastifyAuth from "@fastify/auth";
import { getRelativeMonoRepoPath } from "@zdnevnik/scripting";

import type { AppEnv } from "./types";

Expand Down Expand Up @@ -71,9 +69,7 @@ export async function buildApp(
}

await fastify.register(SecureSession, {
key: fs.readFileSync(
path.join(getRelativeMonoRepoPath("api"), "session_key"),
),
key: Buffer.from(opts.env.SESSION_SECRET, "hex"),
cookieName: opts.env.SESSION_COOKIE_NAME,
cookie: {
httpOnly: true,
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/env/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const envSchema = {
"SESSION_COOKIE_NAME",
"SESSION_COOKIE_DOMAIN",
"SESSION_COOKIE_MAX_AGE",
"SESSION_SECRET",
],
properties: {
DATABASE_URL: {
Expand All @@ -27,7 +28,7 @@ export const envSchema = {
PORT: {
type: "integer",
},
SESSION_KEY_FILE: {
SESSION_SECRET: {
type: "string",
},
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"sv:dev": "pnpm --filter sveltastic vite",
"sv:dev:translations": "pnpm --filter sveltastic dev:translations",
"sv:test": "pnpm --filter sveltastic test",
"sv:test:ui": "pnpm --filter sveltastic test:ui"
"sv:test:ui": "pnpm --filter sveltastic test:ui",
"update_env": "ZDNEVNIK_SSH_CONNECTION=$ZDNEVNIK_SSH_CONNECTION ZDNEVNIK_DESTINATION_DIR=$ZDNEVNIK_DESTINATION_DIR node ./scripts/update_env.js"
},
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion scripts/update_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function main() {
const { stderr } = spawnSync("scp", [`${from}`, `${to}`]);

if (stderr.length > 0) {
console.error(stderr);
console.error(stderr.toString("utf8").trim());
} else {
console.log("Done!");
}
Expand Down

0 comments on commit 8d5a557

Please sign in to comment.