-
Notifications
You must be signed in to change notification settings - Fork 208
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
refactor: extract decode user to util #32
Conversation
39ba47f
to
eab5f0e
Compare
eab5f0e
to
9de6315
Compare
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.
👍
@@ -46,3 +48,15 @@ export function validateCredentials(credentials: Credentials) { | |||
); | |||
} | |||
} | |||
|
|||
// secret should be injected |
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 implemented in the next PR #33
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.
Lovely.
Can you add some tests for the new util function? For example, test the happy path and then an invalid token.
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 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.
👏
Signed-off-by: jannyHou <[email protected]>
115b261
to
7dbe015
Compare
const token = 'fake'; | ||
try { | ||
await decodeAccessToken(token, SECRET); | ||
expect('throws error').to.be.true(); |
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.
Here is a better way for verifying that a call of an async function throws an error:
await expect(decodeAccessToken(token, SECRET))
.to.be.rejectedWith('jwt malformed');
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.
connect to loopbackio/loopback-next#1997
previous PR: #26
Refactor the decoding user code into a util function, so that it could be shared among different controllers other than REST.