@@ -59,7 +59,7 @@ import {
5959 scopesSsoAccountAccess ,
6060 AwsConnection ,
6161} from './connection'
62- import { isSageMaker , isCloud9 } from '../shared/extensionUtilities'
62+ import { isSageMaker , isCloud9 , isAmazonQ } from '../shared/extensionUtilities'
6363import { telemetry } from '../shared/telemetry/telemetry'
6464import { randomUUID } from '../common/crypto'
6565
@@ -300,6 +300,11 @@ export class Auth implements AuthService, ConnectionManager {
300300 metadata : { connectionState : 'unauthenticated' } ,
301301 } )
302302
303+ // Remove the split session logout prompt, if it exists.
304+ if ( ! isAmazonQ ( ) ) {
305+ await globals . context . globalState . update ( SessionSeparationPrompt . instance . dismissKey , true )
306+ }
307+
303308 try {
304309 ; ( await tokenProvider . getToken ( ) ) ?? ( await tokenProvider . createToken ( ) )
305310 const storedProfile = await this . store . addProfile ( id , profile )
@@ -1000,6 +1005,7 @@ export class Auth implements AuthService, ConnectionManager {
10001005 delete this . _declaredConnections [ conn . startUrl ]
10011006 }
10021007}
1008+
10031009/**
10041010 * Returns true if credentials are provided by the environment (ex. via ~/.aws/)
10051011 *
@@ -1012,3 +1018,70 @@ export function hasVendedIamCredentials(isC9?: boolean, isSM?: boolean) {
10121018 isSM ??= isSageMaker ( )
10131019 return isSM || isC9
10141020}
1021+
1022+ type LoginCommand = 'aws.toolkit.auth.manageConnections' | 'aws.codecatalyst.manageConnections'
1023+ /**
1024+ * Temporary class that handles notifiting users who were logged out as part of
1025+ * splitting auth sessions between extensions.
1026+ *
1027+ * TODO: Remove after some time.
1028+ */
1029+ export class SessionSeparationPrompt {
1030+ public readonly dismissKey = 'aws.toolkit.separationPromptDismissed'
1031+ private readonly loginCmdKey = 'aws.toolkit.separationPromptCommand'
1032+
1033+ // Local variable handles per session displays, e.g. we forgot a CodeCatalyst connection AND
1034+ // an Explorer only connection. We only want to display once in this case.
1035+ // However, we don't want to set this at the global state level until a user interacts with the
1036+ // notification in case they miss it the first time.
1037+ #separationPromptDisplayed = false
1038+
1039+ /**
1040+ * Open a prompt for that last used command name (or do nothing if no command name has ever been passed),
1041+ * which is useful to redisplay the prompt after reloads in case a user misses it.
1042+ */
1043+ public async showAnyPreviousPrompt ( ) {
1044+ const cmd = globals . context . globalState . get < string > ( this . loginCmdKey )
1045+ return cmd ? await this . showForCommand ( cmd as LoginCommand ) : undefined
1046+ }
1047+
1048+ /**
1049+ * Displays a sign in prompt to the user if they have been logged out of the Toolkit as part of
1050+ * separating auth sessions between extensions. It will executed the passed command for sign in,
1051+ * (e.g. codecatalyst sign in vs explorer)
1052+ */
1053+ public async showForCommand ( cmd : LoginCommand ) {
1054+ if ( this . #separationPromptDisplayed || globals . context . globalState . get < boolean > ( this . dismissKey ) ) {
1055+ return
1056+ }
1057+
1058+ await globals . context . globalState . update ( this . loginCmdKey , cmd )
1059+
1060+ await telemetry . toolkit_showNotification . run ( async ( ) => {
1061+ telemetry . record ( { id : 'sessionSeparation' } )
1062+ this . #separationPromptDisplayed = true
1063+ void vscode . window
1064+ . showWarningMessage (
1065+ 'Amazon Q and AWS Toolkit no longer share connections. Please sign in again to use AWS Toolkit.' ,
1066+ 'Sign In'
1067+ )
1068+ . then ( async resp => {
1069+ await telemetry . toolkit_invokeAction . run ( async ( ) => {
1070+ if ( resp === 'Sign In' ) {
1071+ telemetry . record ( { action : 'signIn' } )
1072+ await vscode . commands . executeCommand ( cmd )
1073+ } else {
1074+ telemetry . record ( { action : 'dismiss' } )
1075+ }
1076+
1077+ await globals . context . globalState . update ( this . dismissKey , true )
1078+ } )
1079+ } )
1080+ } )
1081+ }
1082+
1083+ static #instance: SessionSeparationPrompt
1084+ public static get instance ( ) {
1085+ return ( this . #instance ??= new SessionSeparationPrompt ( ) )
1086+ }
1087+ }
0 commit comments