cleanup and env example
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
PORT=number
|
||||
JWT_SECRET=string
|
||||
DATABASE_URL=postgresqlConnectionString
|
||||
PASSWORD_HASH_SECRET=verySecretHash
|
||||
PRESALT=prepend
|
||||
POSTSALT=postpend
|
||||
@@ -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());
|
||||
|
||||
@@ -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
|
||||
@@ -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!;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { encodeMessage } from '../helpers/auth.ts';
|
||||
|
||||
type JsonWebToken = {
|
||||
header: {
|
||||
alg: string;
|
||||
|
||||
Reference in New Issue
Block a user