forked from Vijay-K-2003/S.V.S
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
252 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const isLoggedIn = async (req, res, next) => { | ||
if(req.user) | ||
{ | ||
return next(); | ||
} | ||
res.status(401).json({message: "You are Unauthorized to do that"}); | ||
} | ||
|
||
export default isLoggedIn; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import mongoose from "mongoose"; | ||
import findOrCreate from "mongoose-findorcreate"; | ||
const Schema = mongoose.Schema; | ||
|
||
const userSchema = new Schema({ | ||
|
||
|
||
googleId: { | ||
type: String, | ||
required: true | ||
}, | ||
username: { | ||
type: String, | ||
// required: [true, "Name cannot be empty!"] | ||
}, | ||
email: { | ||
type: String, | ||
// required: [true, "Email cannot be empty!"] | ||
}, | ||
password: { | ||
type: String, | ||
// required: [true, "Password cannot be empty!"] | ||
} | ||
}); | ||
userSchema.plugin(findOrCreate); | ||
const User = mongoose.model("User", userSchema); | ||
export default User; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import passport from "passport"; | ||
import {Strategy as GoogleStrategy} from "passport-google-oauth20"; | ||
import dotenv from "dotenv"; | ||
import User from "./models/user.js"; | ||
dotenv.config(); | ||
|
||
passport.use(new GoogleStrategy({ | ||
clientID: process.env.GOOGLE_CLIENT_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
callbackURL: "http://localhost:4000/google/callback/", | ||
passReqToCallback: true | ||
}, | ||
async (req, accessToken, refreshToken, profile, cb) => { | ||
|
||
const user = await User.findOrCreate({googleId: profile.id}, function(err, user){ | ||
console.log(user); | ||
return cb(err, user); | ||
}) | ||
|
||
})); | ||
|
||
passport.serializeUser((user, cb) => { | ||
// done(null, user.id); | ||
// console("Serializing user", user); | ||
cb(null, user.id); | ||
}); | ||
|
||
passport.deserializeUser(async(id, cb)=>{ | ||
const user = await User.findOne({where: {id}}).catch((err) => { | ||
console.log("Error in deserializing"); | ||
cb(err, null); | ||
}); | ||
|
||
if(user) | ||
{ | ||
cb(null, user); | ||
} | ||
|
||
}); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.