Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Luxshan2000 committed Nov 1, 2023
2 parents 265a52e + a8a1472 commit 66012ed
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
41 changes: 36 additions & 5 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.6.0",
"bcrypt": "^5.1.1",
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
Expand Down
20 changes: 11 additions & 9 deletions backend/src/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const jwt = require("jsonwebtoken");
const { GenerateRandomPassword } = require("../utils/string");
const emailModule = require("../utils/email");
const { OTPGenerator } = require("../utils/otpgenerator");
const { default: axios } = require("axios");



require("dotenv").config();
const signup = async (req, res, isWeb) => {
Expand Down Expand Up @@ -133,23 +136,21 @@ exports.googleLogin = async (req, res) => {
return googleLoginBase(req, res, true);
};
const googleLoginBase = async (req, res, isWeb) => {
console.log("hi")
try {
const { token } = req.body;
console.log({ token });
//verfication of user by fetching user information from google
const googleResponse = await fetch(
const googleResponse = await axios.get(
"https://www.googleapis.com/oauth2/v3/userinfo",
{
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
Accept: "application/json",
},
}
).then((res) => res.json());

console.log(googleResponse);
const { email, name } = googleResponse;
)
console.log(googleResponse.data);
const { email, name } = googleResponse.data;
//see if there is an user with that email already
const user = await User.findOne({ email });
console.log({ email, name });
Expand Down Expand Up @@ -197,8 +198,9 @@ const googleLoginBase = async (req, res, isWeb) => {
process.env.SECURITY_KEY,
{ expiresIn: "5hour" }
);
res.cookie("token", newToken);
res.json({ message: "Login successful" });
// res.cookie("token", newToken);

res.json({ message: "Login successful" , newToken });
}
// Send the token in the response
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-router-dom": "^6.15.0",
"react-scripts": "5.0.1",
"recharts": "^2.8.0",
"serve": "^14.2.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down

0 comments on commit 66012ed

Please sign in to comment.