Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/google authentication #6

Open
wants to merge 31 commits into
base: feature/signup
Choose a base branch
from

Conversation

vpul
Copy link
Contributor

@vpul vpul commented May 25, 2019

No description provided.

@vpul vpul requested review from khadkarajesh and AwaleRohin May 25, 2019 17:23
@vpul
Copy link
Contributor Author

vpul commented May 25, 2019

Couldn't reopen pull request for the previous branch, so had to create a new one.

if (await dbQuery.idExists(userInfo)) {
return {
message: token,
statusCode: 200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't hardcode status codes

}
} catch(error) {
console.log(error);
return { message:"Error connecting database", statusCode: 500}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't hardcode messages

const token = await tokenGenerator.token(userInfo.email);
const refresh_token = await tokenGenerator.refresh_token(userInfo.email);

try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we use single try catch?

idExists: async (userInfo) => {
try {
const googleId = await User.findOne({ google_id: userInfo.id });
if (googleId === null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check googleId === null?
dosen't it return true or false?

Copy link
Contributor

@khadkarajesh khadkarajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- coordinate with the @AwaleRohin for success, failure response and status code and messages.

//If the google id already exists in the db, store nothing to the db
if (await dbQuery.idExists(userInfo)) {
return {
message: token,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- follow the feedback dropped to the @AwaleRohin for response and constants.


try {
//If the google id already exists in the db, store nothing to the db
if (await dbQuery.idExists(userInfo)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- you have named the method idExists but you have passed the whole information of userInfo. Pass only user identifier.

@@ -0,0 +1,22 @@
const jwt = require('jsonwebtoken');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- AuthTokenGenerator will be the best name for this file.

if (await dbQuery.idExists(userInfo)) {
return {
message: token,
statusCode: 200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- did you sent the user data on a response?

//Config
const app = express();
app.use(cors());
app.use(bodyParser.json({ type: 'application/*+json' }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- why are you duplicating the things of index.js class?

let response = await googleOauthHandler.getMessage(googleAccessToken);
res.status(response.statusCode).send(response.message);
} catch(error) {
res.status(500).send("Internal Server Error");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- collaborate with @AwaleRohin regarding success and failure response.

idExists: async (userInfo) => {
try {
const googleId = await User.findOne({ google_id: userInfo.id });
if (googleId === null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- directly return return googleId === null its a expression it returns true or false by itself. You don't need to return true or false.

refresh_token
}
try {
User.create(user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- don't you need to use await syntax for this?

message: token,
statusCode: 200
};
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- you can use else if

@vpul vpul requested review from Xkid0525 and shakyasaijal May 27, 2019 05:36
@vpul
Copy link
Contributor Author

vpul commented May 27, 2019

@khadkarajesh Made changes suggested in the review.

index.js Outdated
@@ -24,4 +27,5 @@ app.get('/', (req, res) => {
app.use(bodyParser.json())
app.use(cors())
app.use(morgan('combined'))
app.use('/mentors/', signup)
app.use('v1/mentors/', signup)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vipul- is it correct resource name for mentor signup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants