diff --git a/backend/.env.example b/backend/.env.example new file mode 100644 index 0000000..cbbd06e --- /dev/null +++ b/backend/.env.example @@ -0,0 +1,6 @@ +PORT=number +JWT_SECRET=string +DATABASE_URL=postgresqlConnectionString +PASSWORD_HASH_SECRET=verySecretHash +PRESALT=prepend +POSTSALT=postpend diff --git a/backend/src/helpers/auth.ts b/backend/src/helpers/jwt.ts similarity index 100% rename from backend/src/helpers/auth.ts rename to backend/src/helpers/jwt.ts diff --git a/backend/src/index.ts b/backend/src/index.ts index 0f41afd..4f64b62 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -5,7 +5,6 @@ import { blocksRouter } from './routes/blocks.ts'; import { imagesRouter } from './routes/images.ts'; import { authRouter } from './routes/auth.ts'; import { usersRouter } from './routes/users.ts'; -import { auth } from './middleware/auth.ts'; const app = express(); app.use(express.json()); diff --git a/backend/src/middleware/auth.ts b/backend/src/middleware/loadJWT.ts similarity index 94% rename from backend/src/middleware/auth.ts rename to backend/src/middleware/loadJWT.ts index 7e96d08..009580e 100644 --- a/backend/src/middleware/auth.ts +++ b/backend/src/middleware/loadJWT.ts @@ -1,8 +1,8 @@ import { Request, Response, NextFunction } from "express"; import JsonWebToken, { defaultJWT } from '../types/JsonWebToken.ts'; -import { verifySignature, decodeJWT } from '../helpers/auth.ts'; +import { verifySignature, decodeJWT } from '../helpers/jwt.ts'; -export function auth( +export function loadJWT( req: Request, res: Response, next: NextFunction diff --git a/backend/src/routes/auth.ts b/backend/src/routes/auth.ts index 003c8e4..9464abf 100644 --- a/backend/src/routes/auth.ts +++ b/backend/src/routes/auth.ts @@ -3,7 +3,7 @@ import crypto from 'crypto'; import { eq } from 'drizzle-orm'; import { users } from '../db/schema.ts'; import express, { Request, Response } from "express"; -import { generateSignedJWT, base64UrlDecode } from '../helpers/auth.ts'; +import { generateSignedJWT, base64UrlDecode } from '../helpers/jwt.ts'; const db = drizzle(process.env.DATABASE_URL!); const hashSecret = process.env.PASSWORD_HASH_SECRET!; diff --git a/backend/src/routes/users.ts b/backend/src/routes/users.ts index f4a0027..283634f 100644 --- a/backend/src/routes/users.ts +++ b/backend/src/routes/users.ts @@ -2,12 +2,12 @@ import { drizzle } from 'drizzle-orm/node-postgres'; import { eq } from 'drizzle-orm'; import { users } from '../db/schema.ts'; import express, { Request, Response } from "express"; -import { auth } from '../middleware/auth.ts'; +import { loadJWT } from '../middleware/loadJWT.ts'; const db = drizzle(process.env.DATABASE_URL!); export const usersRouter = express.Router(); -usersRouter.get("/getUsers", auth, async (req: Request, res: Response) => { +usersRouter.get("/getUsers", loadJWT, async (req: Request, res: Response) => { if (req.jwt.payload.prm != 77) return res .status(403) diff --git a/backend/src/types/JsonWebToken.ts b/backend/src/types/JsonWebToken.ts index b3027b2..d9ee690 100644 --- a/backend/src/types/JsonWebToken.ts +++ b/backend/src/types/JsonWebToken.ts @@ -1,5 +1,3 @@ -import { encodeMessage } from '../helpers/auth.ts'; - type JsonWebToken = { header: { alg: string;