Skip to content

Commit

Permalink
🔒wrote preliminary login function
Browse files Browse the repository at this point in the history
  • Loading branch information
Plebbaroni committed Nov 12, 2024
1 parent a7463ef commit 9c1eb51
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend/.env.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DATABASE_URL="postgres://postgres:postgres@localhost:5432"
DIRECT_URL="postgres://postgres:postgres@localhost:5432"
SESSION_SECRET=7#mRF9^QnD
NODE_ENV=test
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
# Keep environment variables out of version control
.env
.env
.env.test
12 changes: 10 additions & 2 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express, { Request, Response } from "express";
import session from "express-session";
import cors from "cors";
import { LoginBody, TypedRequest } from "./requestTypes";
import { LoginBody, TypedRequest, UserIdBody } from "./requestTypes";
import bcrypt from "bcrypt";
import { LoginErrors } from "./interfaces";
import { PrismaClient, Prisma, UserType, User } from "@prisma/client";
Expand Down Expand Up @@ -93,7 +93,7 @@ app.post(
}
);

app.post("/login", async (req: TypedRequest<LoginBody>, res: Response) => {
app.post("/auth/login", async (req: TypedRequest<LoginBody>, res: Response) => {
try {
const { username, password } = req.body;

Expand Down Expand Up @@ -123,6 +123,14 @@ app.post("/login", async (req: TypedRequest<LoginBody>, res: Response) => {
}
});

app.get("/user", async (req: TypedRequest<UserIdBody>, res: Response) => {
if (req.session.userId === req.body.userId) {
return res.status(200)
} else {
return res.status(401)
}
});

app.get("/hello", () => {
console.log("Hello World!");
});
Expand Down
4 changes: 4 additions & 0 deletions backend/src/requestTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export interface LoginBody {
password: string;
userType: UserType;
}

export interface UserIdBody {
userId: number
}

0 comments on commit 9c1eb51

Please sign in to comment.