Skip to content

Commit

Permalink
cookie error test3
Browse files Browse the repository at this point in the history
  • Loading branch information
Puneet-NJ committed Jan 5, 2025
1 parent ef0f354 commit 9a1ac3c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ app.use(
cors({
origin: "https://course-app.puneetnj.fun",
credentials: true,
methods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"],
allowedHeaders: ["Content-Type", "Authorization"],
})
);

Expand Down
2 changes: 1 addition & 1 deletion backend/src/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.get(
return;
}

res.json({ loggedIn: false });
res.json({ loggedIn: false, msg: "Token was present" });
} catch (err) {
res.status(500).json({ msg: "Internal Server Error" });
}
Expand Down
4 changes: 3 additions & 1 deletion backend/src/v1/middleware/tokenPresent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const tokenPresent = (req: Request, res: Response, next: NextFunction) => {
if (!token) {
res.locals.tokenPresent = false;

res.json({ loggedIn: false });
console.log("TOken is absent");

res.json({ loggedIn: false, msg: "Token is not present" });
return;
}

Expand Down
6 changes: 4 additions & 2 deletions backend/src/v1/routes/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ adminRouter.post("/signup", async (req, res) => {
res.cookie("auth", token, {
httpOnly: true,
sameSite: "none",
secure: process.env.NODE_ENV === "production",
secure: true,
path: "/",
});

res.json({ msg: "Sign up successful" });
Expand Down Expand Up @@ -91,7 +92,8 @@ adminRouter.post("/signin", async (req, res) => {
res.cookie("auth", token, {
httpOnly: true,
sameSite: "none",
secure: process.env.NODE_ENV === "production",
secure: true,
path: "/",
});

res.json({ msg: "Sign in successful" });
Expand Down
6 changes: 4 additions & 2 deletions backend/src/v1/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ userRouter.post("/signup", async (req, res) => {
res.cookie("auth", token, {
httpOnly: true,
sameSite: "none",
secure: process.env.NODE_ENV === "production",
secure: true,
path: "/",
});

res.json({ msg: "Sign up successful" });
Expand Down Expand Up @@ -91,7 +92,8 @@ userRouter.post("/signin", async (req, res) => {
res.cookie("auth", token, {
httpOnly: true,
sameSite: "none",
secure: process.env.NODE_ENV === "production",
secure: true,
path: "/",
});

res.json({ msg: "Sign in successful" });
Expand Down

0 comments on commit 9a1ac3c

Please sign in to comment.