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

refactored logout-service #319

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kevinlaiGH
Copy link

  1. Switch to private properties.
  2. Use async/await consistently instead of mixing with .catch.
  3. Use a constant for the maximum check count instead of a magic number.

@motdotla
Copy link
Member

motdotla commented Nov 7, 2023

Thanks for this @kevinlaiGH. Appreciate the contribution!

That said, can you please remove all the semicolons. This project somewhat follows 'standardjs' styling (though I need to get it added as part of the build/linting steps).

Also, can you remove the private functions. I'm not a fan of them in typescript/js code since JavaScript doesn't have a true concept of private functions. Also this is an open source library so I err on keeping functions public. (I personally hate when I need to do a simple monkey patch or method overload and can't because the library writer protected functions)

Otherwise, much better removing the .catch.

@motdotla
Copy link
Member

motdotla commented Nov 7, 2023

Also, if you are interested in cleaning up style/linting, we really need a contribution to add standardjs, but for typescript. Would love that if you are interested in contributing more! https://standardjs.com/

@kevinlaiGH
Copy link
Author

kevinlaiGH commented Nov 8, 2023

Thanks for the suggestions @motdotla. I have changed it accordingly.
Could you review it again please?
Cheers!

Copy link
Member

@motdotla motdotla left a comment

Choose a reason for hiding this comment

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

a couple small details

if (!this.yes) {
this.log.local(`Logout URL: ${this.logoutUrl}`)
const answer = await CliUx.ux.prompt(`${chalk.dim(this.log.pretextLocal)}Press ${chalk.green('y')} (or any key) to logout and revoke credential (.env.me) or ${chalk.yellow('q')} to exit`)
if (answer === 'q' || answer === 'Q') {
if (answer.toLowerCase() === 'q') {
Copy link
Member

Choose a reason for hiding this comment

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

can we have this also strip any spaces? - in case the user accidentally hits the space bar and then q

}

async run(): Promise<void> {
await this.logout()
}

async logout(tip = true): Promise<void> {
async logout(showInstructions = true): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

better name 👍

import {CliUx} from '@oclif/core'
import {LogService} from '../services/log-service'
import {AbortService} from '../services/abort-service'
import axios, { AxiosRequestConfig } from 'axios'
Copy link
Member

Choose a reason for hiding this comment

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

all these extra spaces, can you remove those back to how things were - to keep the same style. i know this is getting nitpicky, but let's do that until ts-standard gets added to the repo.

// 404 - keep trying
await CliUx.ux.wait(2000) // check every 2 seconds
await this.check(tip) // check again
} else if (this.checkCount < LogoutService.MAX_CHECK_COUNT) {
Copy link
Member

Choose a reason for hiding this comment

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

small but very nice improvement. MAX_CHECK_COUNT 💛

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.

None yet

2 participants