Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Implemented basic validation of user logins #268

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
# GOOGLE_CONSUMER_KEY=dlkjxaxxxxxxxxdlkfjalskjda9sokpopr.apps.googleusercontent.com
# GOOGLE_CONSUMER_SECRET=XoDoijdasdj_ooPwerO
# GOOGLE_CALLBACK=http://localhost/auth/google/callback
# [email protected],[email protected]
# if you aim to contribute and run the project via npm then use : GOOGLE_CALLBACK=http://localhost:8080/auth/google/callback
GOOGLE_CONSUMER_KEY=
GOOGLE_CONSUMER_SECRET=
GOOGLE_CALLBACK=
GOOGLE_USERS=

# Postgres user and database information
# - These variables should match your Postgres configuration
Expand Down
7 changes: 6 additions & 1 deletion server/config/passport/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ module.exports = (passport, secret) => {
googleId: profile.id
}
}).then(userExists => {
let email = profile._json.emails[0].value
if (secret.users && secret.users.indexOf(email) == -1) {
throw new Error('User not found!');
}

if (userExists) {
done(null, userExists);
} else {
Expand All @@ -21,7 +26,7 @@ module.exports = (passport, secret) => {
return db.user.create({
googleId: profile.id,
token: token,
email: profile._json.emails[0].value,
email: email,
name: profile.displayName,
picture: profile._json.image.url
}, { transaction: t })
Expand Down
3 changes: 2 additions & 1 deletion server/config/secrets.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = {
google: {
consumerKey: process.env.GOOGLE_CONSUMER_KEY,
consumerSecret: process.env.GOOGLE_CONSUMER_SECRET,
callbackURL: process.env.GOOGLE_CALLBACK || 'http://localhost:8080/auth/google/callback'
callbackURL: process.env.GOOGLE_CALLBACK || 'http://localhost:8080/auth/google/callback',
users: process.env.GOOGLE_USERS
},

};