Skip to content

Commit

Permalink
logout on token expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeManSu committed Dec 18, 2024
1 parent 29b1b74 commit 4e6aed7
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/cli/validateToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { API as APIInterface } from '@metacall/protocol/protocol';
import { unlink } from 'fs/promises';
import { configFilePath, save } from '../config';
import { auth } from '../auth';
import { configFilePath, defaultPath, load, save } from '../config';
import { exists } from '../utils';
import args from './args';
import { error, info } from './messages';
Expand Down Expand Up @@ -32,11 +33,18 @@ const validateToken = async (api: APIInterface): Promise<void> => {

(await exists(configFile)) && (await unlink(configFile));

info('Try to login again!');
info('Token expired, initiating token-based login...');

return error(
`Token validation failed, potential causes include:\n\t1) The JWT may be mistranslated (Invalid Signature).\n\t2) JWT might have expired.`
);
try {
const config = await load(defaultPath);

const newToken = await auth(config);
// Save the new token
await save({ token: newToken });
return;
} catch (loginErr) {
return error('Token validation failed. Please try again.');
}
}
};

Expand Down

0 comments on commit 4e6aed7

Please sign in to comment.