Skip to content

Commit

Permalink
feat: force refresh auth token
Browse files Browse the repository at this point in the history
  • Loading branch information
benjlevesque committed Mar 1, 2023
1 parent 12b4020 commit 75536fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token>(accessToken);

if (!this.isExpired(parsed)) return;
if (!force && !this.isExpired(parsed)) return;

console.log('Refreshing token');

Expand Down
9 changes: 8 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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));

Expand Down

0 comments on commit 75536fb

Please sign in to comment.