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 { imagesRouter } from './routes/images.ts';
|
||||||
import { authRouter } from './routes/auth.ts';
|
import { authRouter } from './routes/auth.ts';
|
||||||
import { usersRouter } from './routes/users.ts';
|
import { usersRouter } from './routes/users.ts';
|
||||||
import { auth } from './middleware/auth.ts';
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
import JsonWebToken, { defaultJWT } from '../types/JsonWebToken.ts';
|
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,
|
req: Request,
|
||||||
res: Response,
|
res: Response,
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
@@ -3,7 +3,7 @@ import crypto from 'crypto';
|
|||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import { users } from '../db/schema.ts';
|
import { users } from '../db/schema.ts';
|
||||||
import express, { Request, Response } from "express";
|
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 db = drizzle(process.env.DATABASE_URL!);
|
||||||
const hashSecret = process.env.PASSWORD_HASH_SECRET!;
|
const hashSecret = process.env.PASSWORD_HASH_SECRET!;
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import { drizzle } from 'drizzle-orm/node-postgres';
|
|||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
import { users } from '../db/schema.ts';
|
import { users } from '../db/schema.ts';
|
||||||
import express, { Request, Response } from "express";
|
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!);
|
const db = drizzle(process.env.DATABASE_URL!);
|
||||||
export const usersRouter = express.Router();
|
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)
|
if (req.jwt.payload.prm != 77)
|
||||||
return res
|
return res
|
||||||
.status(403)
|
.status(403)
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { encodeMessage } from '../helpers/auth.ts';
|
|
||||||
|
|
||||||
type JsonWebToken = {
|
type JsonWebToken = {
|
||||||
header: {
|
header: {
|
||||||
alg: string;
|
alg: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user