From 4dfa0dc9e1329c28cd69c2262cdc8f7af053a081 Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Wed, 20 Sep 2023 11:26:40 +0100 Subject: [PATCH] Handle account session expiry --- src/extension.ts | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a4c51e19..db229124 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -73,12 +73,31 @@ export async function activate(context: vscode.ExtensionContext) { const userService = new UserService(globalStateTokenStorage); const accessToken = userService.getLinkedToken(); + if (accessToken !== null) { + const valid = await validateAccessToken(accessToken); + vscode.commands.executeCommand('setContext', 'intuita.signedIn', valid); + + if (!valid) { + userService.unlinkUserIntuitaAccount(); + const decision = await vscode.window.showInformationMessage( + 'You are signed out because your session has expired.', + 'Do you want to sign in again?', + ); + if (decision === 'Do you want to sign in again?') { + const searchParams = new URLSearchParams(); - vscode.commands.executeCommand( - 'setContext', - 'intuita.signedIn', - accessToken !== null, - ); + searchParams.set( + SEARCH_PARAMS_KEYS.COMMAND, + 'accessTokenRequested', + ); + + const url = new URL('https://codemod.studio'); + url.search = searchParams.toString(); + + vscode.commands.executeCommand('intuita.redirect', url); + } + } + } const configurationContainer = buildContainer(getConfiguration());