Skip to content

Commit dc650bc

Browse files
authored
fix: read JWT secret from environment variable instead of hardcoded value (#5)
1 parent 7082249 commit dc650bc

6 files changed

Lines changed: 12 additions & 1 deletion

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Required — used to sign JWTs. Generate with: openssl rand -hex 32
2+
SECRET_KEY=

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828

2929
- name: Test
3030
run: pytest backend/tests/
31+
env:
32+
SECRET_KEY: ci-test-secret
3133

3234
frontend:
3335
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ yarn-error.log*
2626
.pnpm-debug.log*
2727

2828
# local env files
29+
.env
2930
.env*.local
3031

3132
# vercel

backend/app/api/users.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# app/api/users.py
22

3+
import os
34
from typing import Optional
45

56
from fastapi import APIRouter, Depends, HTTPException, Request, Response, status
@@ -13,7 +14,7 @@
1314

1415
# ─── CONFIG ──────────────────────────────────────────────────────────────
1516

16-
SECRET_KEY = "CHANGE_THIS_TO_A_RANDOM_SECRET" # override from env in prod
17+
SECRET_KEY = os.environ["SECRET_KEY"]
1718
ALGORITHM = "HS256"
1819

1920
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")

backend/tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os
2+
3+
os.environ.setdefault("SECRET_KEY", "test-secret")
4+
15
import pytest
26
from sqlalchemy import text
37
from sqlmodel import Session, SQLModel, create_engine

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
- db
1111
environment:
1212
DEV_MODE: "${DEV_MODE:-}"
13+
SECRET_KEY: "${SECRET_KEY}"
1314
volumes:
1415
- ./dsa-flash-cards:/data/flashcards
1516

0 commit comments

Comments
 (0)