From 75536fbcdbb056547625bd85f846fd72dd46a312 Mon Sep 17 00:00:00 2001 From: Benjamin Levesque <14175665+benjlevesque@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:10:13 +0100 Subject: [PATCH] feat: force refresh auth token --- src/auth/auth.service.ts | 4 ++-- src/main.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index c15c2e8..453d0dd 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -38,12 +38,12 @@ export class AuthService { return { accessToken, parsed }; } - public async refresh() { + public async refresh(force?: boolean) { const { accessToken, refreshToken } = this.config.values; if (!refreshToken) return; const parsed = this.parseJwt(accessToken); - if (!this.isExpired(parsed)) return; + if (!force && !this.isExpired(parsed)) return; console.log('Refreshing token'); diff --git a/src/main.ts b/src/main.ts index ac5a07c..1501e82 100644 --- a/src/main.ts +++ b/src/main.ts @@ -53,6 +53,10 @@ async function bootstrap() { describe: 'The format of the texts', default: 'human', }) + .option('refresh-token', { + type: 'boolean', + desc: 'Forces the refresh of the token', + }) .option('json', { type: 'boolean', describe: 'Alias for --format json' }) .help('h') .alias('h', 'help') @@ -62,7 +66,10 @@ async function bootstrap() { .scriptName('rf') .middleware(async (args) => { if (['auth:login', 'init'].includes(String(args._[0]))) return; - await app.get(AuthService).refresh().catch(errorHandler); + await app + .get(AuthService) + .refresh(args['refresh-token']) + .catch(errorHandler); }) .command('repl', false, () => repl(AppModule));