From 7598699913708345ef86529a0db270055914493b Mon Sep 17 00:00:00 2001 From: ridima Date: Thu, 21 May 2026 20:53:08 +0530 Subject: [PATCH 1/3] added google authentication --- package.json | 16 ++-------------- src/components/Navbar.tsx | 12 +++++++++++- src/main.tsx | 7 ++++++- src/pages/Login/Login.tsx | 19 +++++++++++++++++-- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 43ad31cc..556188f5 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,6 @@ "private": true, "version": "0.0.0", "type": "module", - "scripts": { "dev": "vite --host", "build": "vite build", @@ -14,17 +13,18 @@ "docker:dev": "docker compose --profile dev up --build", "docker:prod": "docker compose --profile prod up -d --build" }, - "dependencies": { "@emotion/react": "^11.11.3", "@emotion/styled": "^11.11.0", "@mui/icons-material": "^5.15.6", "@mui/material": "^5.15.6", "@primer/octicons-react": "^19.25.0", + "@react-oauth/google": "^0.13.5", "@vitejs/plugin-react": "^4.3.3", "axios": "^1.7.7", "express": "^5.2.1", "framer-motion": "^12.23.12", + "jwt-decode": "^4.0.0", "lucide-react": "^0.525.0", "mongoose": "^9.6.2", "octokit": "^4.0.2", @@ -37,7 +37,6 @@ "recharts": "^3.8.1", "tailwindcss": "^3.4.14" }, - "devDependencies": { "@eslint/js": "^9.13.0", "@testing-library/jest-dom": "^6.9.1", @@ -49,33 +48,22 @@ "@types/react-dom": "^18.3.7", "@types/react-redux": "^7.1.34", "@types/react-router-dom": "^5.3.3", - "@vitejs/plugin-react-swc": "^3.5.0", - "autoprefixer": "^10.4.20", "bcryptjs": "^3.0.3", - "eslint": "^9.13.0", "eslint-plugin-react": "^7.37.2", "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.14", - "express-session": "^1.18.2", - "globals": "^15.11.0", - "jasmine": "^5.13.0", "jasmine-spec-reporter": "^7.0.0", - "jsdom": "^29.1.1", - "passport": "^0.7.0", "passport-local": "^1.0.0", - "supertest": "^7.2.2", - "typescript-eslint": "^8.59.3", - "vite": "^5.4.10", "vitest": "^4.1.6" } diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index fd5eac86..0643733c 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -52,10 +52,20 @@ const Navbar: React.FC = () => { Contributors - + {localStorage.getItem("token") ? ( + + ) : ( Login + )} {/* Theme Toggle */} - + { + const token = credentialResponse.credential; + if (!token) { + return; + } + try { + localStorage.setItem("token", token); + navigate("/"); + } catch (err) { + } + }} + /> {/* Message */} {message && (
Date: Thu, 21 May 2026 22:15:41 +0530 Subject: [PATCH 2/3] Finalized the design for "sign in with google" and added a GoogleAuth.md with instructions to how to set up the google client id. --- GoogleAuth.md | 41 +++++++++++++++++++++++++++++++++++++++ src/pages/Login/Login.tsx | 4 +++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 GoogleAuth.md diff --git a/GoogleAuth.md b/GoogleAuth.md new file mode 100644 index 00000000..550c42b5 --- /dev/null +++ b/GoogleAuth.md @@ -0,0 +1,41 @@ +Authentication (Google OAuth) + +This project uses Google OAuth 2.0 for user authentication via @react-oauth/google. + +``` +Setup Required +1. Create Google OAuth Client + -> Go to Google Cloud Console: + (https://console.cloud.google.com/apis/credentials?utm_source=chatgpt.com) + + -> Create OAuth Client ID + -> Choose Web application + +2. Configure Authorized Origins + ->Development + http://localhost:5173 (the port where your server is running i.e after running npm run dev) + ->Production + https://your-domain.com (the deployed url, only imp when you want the app to go live (not for your local computer)) + if working on local computer + the other javascript origin will be http://localhost + +3. Configure Redirect URIs + + ->Development + http://localhost:5173 + -> Production + https://your-domain.com (not necessary if you are not gonna deploy the app) + +``` + +Environment Variables +Create a .env file in the root: + +VITE_CLIENT_ID=your_google_client_id + +⚠️ This is required for Google login to work. + +`` + +That's it! +Google authentication will now work all fine ! \ No newline at end of file diff --git a/src/pages/Login/Login.tsx b/src/pages/Login/Login.tsx index 4e8fcbb8..9260a377 100644 --- a/src/pages/Login/Login.tsx +++ b/src/pages/Login/Login.tsx @@ -134,7 +134,8 @@ const Login: React.FC = () => { {isLoading ? "Signing in..." : "Sign In"} - + { const token = credentialResponse.credential; if (!token) { @@ -147,6 +148,7 @@ const Login: React.FC = () => { } }} /> +
{/* Message */} {message && (
Date: Thu, 21 May 2026 22:32:37 +0530 Subject: [PATCH 3/3] fixed some minor bugs in the ui --- src/components/Navbar.tsx | 21 ++++++++++++++++++++- src/pages/Login/Login.tsx | 9 ++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 0643733c..b2738a15 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -140,7 +140,26 @@ const Navbar: React.FC = () => { > Contributors - + {localStorage.getItem("token") ? ( + + ) : ( + + Login + + )} {
{ + onSuccess={async (credentialResponse) => { const token = credentialResponse.credential; if (!token) { return; } try { - localStorage.setItem("token", token); - navigate("/"); + const res = await axios.post(`${backendUrl}/api/auth/google`, { credential: token }); + + localStorage.setItem("token", res.data.token); + + navigate("/"); } catch (err) { + setMessage("Login failed. Please try again."); + } }} />