auth stuff

This commit is contained in:
2026-05-23 18:26:13 -05:00
parent 9e645fe06c
commit b1625d471e
2 changed files with 15 additions and 10 deletions
+14 -9
View File
@@ -1,21 +1,26 @@
import { Request, Response, NextFunction } from "express"; import { Request, Response, NextFunction } from "express";
import { drizzle } from 'drizzle-orm/node-postgres';
import { users } from "../db/schema.ts"; import { users } from "../db/schema.ts";
import { eq } from 'drizzle-orm';
const db = drizzle(process.env.DATABASE_URL!);
export async function auth( export async function auth(
req: Request, req: Request,
res: Response, res: Response,
next: NextFunction next: NextFunction
) { ) {
// Either get the user profile of the logged in user, // read/decode jwt
// or default to anonymous permissions
const token = req.header("Authentication");
if (!token) {
return res.status(401).json({
error: "Missing Token",
});
};
next(); next();
}; };
async function getUserPermissions(userId: string) {
const resp = await db
.select({ perms: users.permissions })
.from(users)
.where(eq(users.id, userId));
return resp;
}
+1 -1
View File
@@ -7,7 +7,7 @@ import { auth } from '../middleware/auth.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("/getUser/:userId", auth, async (req: Request, res: Response) => { usersRouter.get("/getUser/:userId", async (req: Request, res: Response) => {
const { userId } = req.params; const { userId } = req.params;
const resp = await db.select() const resp = await db.select()