-
Notifications
You must be signed in to change notification settings - Fork 5
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
Setup boilerplate, Added Auth #1
Conversation
temanisparsh
commented
Jul 8, 2020
- Setup a project structure
- Setup auth service using passport-jwt
- Setup basic login / register auth flows
Is this ready for merge? |
@aniketnk Not yet, it needs to be updated with these things:
|
Also please add comments wherever possible 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added comments in a few places. Resolve and/or reply if it needs to be discussed.
Can you also work on a README or CONTRIBUTING.md with dev setup instructions.
|
||
import passport from 'passport'; | ||
|
||
import config from './config'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need any error handling if the config file is not present?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Umm, I have an example config file and I will add in the instructions to create config in the rEADME, I don't see a reason to add error handling for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
But I think that a 'file not found' error doesn't provide the developer with enough information. That's why if we had some config store, and if that import failed we could throw an appropriate detailed error message. And that would have to be handled only in one place(where the store is initialised).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I will update it so that it throws an appropriate error for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the error it throws for now. Is this fine?
6 import config from './config';
~~~~~~~~~~
at createTSError (/home/sparsh/Desktop/Sparsh/Projects/alcoding/posterior/node_modules/ts-node/src/index.ts:434:12)
at reportTSError (/home/sparsh/Desktop/Sparsh/Projects/alcoding/posterior/node_modules/ts-node/src/index.ts:438:19)
at getOutput (/home/sparsh/Desktop/Sparsh/Projects/alcoding/posterior/node_modules/ts-node/src/index.ts:578:36)
at Object.compile (/home/sparsh/Desktop/Sparsh/Projects/alcoding/posterior/node_modules/ts-node/src/index.ts:775:32)
at Module.m._compile (/home/sparsh/Desktop/Sparsh/Projects/alcoding/posterior/node_modules/ts-node/src/index.ts:858:43)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .ts] (/home/sparsh/Desktop/Sparsh/Projects/alcoding/posterior/node_modules/ts-node/src/index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
[nodemon] app crashed - waiting for file changes before starting...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this error message is not informative enough. Let's open an issue to solve this config feature.
}) | ||
); | ||
|
||
export const verifyUser = passport.authenticate('jwt', { session: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the JWT doesn't have any user information apart from the passport "id", does it do a database lookup to verify each time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does a DB lookup everytime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. That's an unnecessary overhead. Any way around this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have to look into this. I came up with a few solutions but most of them seem to have some or the other side effect.
Think of an ideal scenario where we have established a system where DB lookup isn't needed. Now I have logged in from 2 systems s1 and s2. If I were to change my password from s2 and then try to access my account from s1..there has to be a DB lookup to invalidate those credentials right? This would contradict the first assumption.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this issue won't arise once we have the refresh token mechanism. Let's add that as an issue and work on it later!
@@ -0,0 +1,27 @@ | |||
import User, { IUser } from '../models/user.model'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some documentation needed here too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was some hook that applied changes after a commit was made, I'm not sure where that's configured, it didn't prevent the commit from happening, it formatted a few files after the commit. Could that behaviour be changed?
@souravtecken Yeah, it's a pre commit hook which runs the linter and checks other rules too. |
LGTM, let's merge this so other work can go on in parallel !! |
Can you clean up the commit history so we can "rebase and merge"? |
* added dependencies * added auth model and router * setup passport config
* convert to typescript * add types as ddev dependencies * add eslint and prettier config * setup nodemon dev server