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

refactor: extract decode user to util #32

Merged
merged 1 commit into from
Jan 30, 2019
Merged

Conversation

jannyHou
Copy link
Contributor

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.

Copy link
Contributor

@b-admike b-admike left a 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
Copy link
Contributor Author

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

Copy link
Member

@bajtos bajtos left a 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.

Copy link
Contributor

@nabdelgadir nabdelgadir left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@b-admike b-admike left a comment

Choose a reason for hiding this comment

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

👏

@jannyHou jannyHou merged commit 1d705b7 into master Jan 30, 2019
const token = 'fake';
try {
await decodeAccessToken(token, SECRET);
expect('throws error').to.be.true();
Copy link
Member

Choose a reason for hiding this comment

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

@jannyHou

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');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bajtos Thanks! I will address the feedback in #37

@jannyHou jannyHou deleted the auth/util-refactor branch March 28, 2019 16:07
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