Skip to content

Commit

Permalink
Additional support for Google chrome and enhanced security(in sign in…
Browse files Browse the repository at this point in the history
… with google and cookie usage)
  • Loading branch information
sikehish committed Jun 11, 2024
1 parent 1337e43 commit 4daa91a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions backend/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export const userLogin = asyncWrapper(async (req: Request, res: Response) => {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
// secure: true, //for ngrok/https, its true else false
// sameSite: 'strict',
sameSite: "none",
sameSite: 'strict',
// sameSite: "none",
maxAge: 5 * 24 * 60 * 60 * 1000
});

Expand Down Expand Up @@ -178,8 +178,8 @@ export const adminLogin = asyncWrapper(async (req, res) => {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
// secure: true,
// sameSite: 'strict',
sameSite: "none",
sameSite: 'strict',
// sameSite: "none",
maxAge: 5 * 24 * 60 * 60 * 1000
});

Expand Down
7 changes: 4 additions & 3 deletions backend/routes/oauthRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ router.get("/login/success", successHandler);

router.get("/login/failed", failureHandler);

router.get("/google", passport.authenticate("google", { scope: ["profile", "email"] }));
router.get("/google", passport.authenticate("google", { scope: ["profile", "email"], prompt: 'select_account' }));

// Google OAuth callback URL
router.get('/google/callback', passport.authenticate('google', { session: false, failureRedirect:`${process.env.CLIENT_URL}/failed` }), (req, res) => {
router.get('/google/callback', passport.authenticate('google', { session: false, failureRedirect:`${process.env.CLIENT_URL}/failed`,prompt: 'select_account' }), (req, res) => {
console.log("HAHAHAHAH")
if (req.user) {
const user: any = req.user;
Expand All @@ -23,7 +23,8 @@ router.get('/google/callback', passport.authenticate('google', { session: false,
// Set the cookie
res.cookie('token', token, {
httpOnly: true,
sameSite: 'none',
sameSite: 'strict',
// sameSite: 'none',
maxAge: 5 * 24 * 60 * 60 * 1000
});

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function Login() {
e.preventDefault();
const callbackUrl =
import.meta.env.VITE_NODE_ENV === "development"
? "http://localhost:3000/api/oauth/google/callback"
: "/api/oauth/google/callback";
? "http://localhost:3000/api/oauth/google"
: "/api/oauth/google";

window.open(callbackUrl, "_self");
};
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/pages/auth/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ function Signup() {
e.preventDefault();
const callbackUrl =
import.meta.env.VITE_NODE_ENV === "development"
? "http://localhost:3000/api/oauth/google/callback"
: "/api/oauth/google/callback";
? "http://localhost:3000/api/oauth/google"
: "/api/oauth/google";

window.open(callbackUrl, "_self");
};
// // OR

// OR
// const googleAuth = (e: any) => {
// e.preventDefault()
// window.open(
Expand Down

0 comments on commit 4daa91a

Please sign in to comment.