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

chore: refactor auth to async await #548

Merged
merged 1 commit into from
Jun 4, 2019

Conversation

lili2311
Copy link
Contributor

@lili2311 lili2311 commented Jun 2, 2019

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

  • Refactor auth handling to use async/await instead of promises
  • Slightly refactor to simplify + for readability

Where should the reviewer start?

auth/index.ts

How should this be manually tested?

  • Build with npm run build & then test out using snyk auth

@lili2311 lili2311 added the 🚧 WIP Work In Progress label Jun 2, 2019
@lili2311 lili2311 force-pushed the chore/refactor-auth-to-async-await branch 4 times, most recently from 85a8662 to 819d46e Compare June 3, 2019 08:18
@lili2311 lili2311 self-assigned this Jun 3, 2019
@lili2311 lili2311 force-pushed the chore/refactor-auth-to-async-await branch from 819d46e to 11b51f1 Compare June 3, 2019 08:34
@lili2311 lili2311 removed the 🚧 WIP Work In Progress label Jun 3, 2019

return spinner(lbl).then(() => {
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

you are dropping spinner here? Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two reasons:

  • it prints Waiting... and then is clears it a few seconds later. Seems not very helpful
  • the way previous code was written means it cleared the spinner after getting the value back, i a promise chain couldn't see a nice way to add this into the refactored code as we return the value.

Copy link
Contributor

Choose a reason for hiding this comment

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

you could return "testAuthComplete().then(spinner.clear)"

But if you feel that the spinner was useless, LET IT DIE.

const apiUrl = url.parse(config.API);
const authUrl = apiUrl.protocol + '//' + apiUrl.host;
const debug = Debug('snyk-auth');
let attemptsLeft = 0;

module.exports = auth;

function resetAttempts() {
attemptsLeft = 30;
Copy link
Contributor

Choose a reason for hiding this comment

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

30 is a lot. Do you know how was this number chosen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't perhaps worth asking in slack, it does seem like a lot


return spinner(lbl).then(() => {
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

you could return "testAuthComplete().then(spinner.clear)"

But if you feel that the spinner was useless, LET IT DIE.

@lili2311 lili2311 merged commit ca26df3 into master Jun 4, 2019
@lili2311 lili2311 deleted the chore/refactor-auth-to-async-await branch June 4, 2019 09:43
@snyksec
Copy link

snyksec commented Jun 5, 2019

🎉 This PR is included in version 1.172.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants