Skip to content

Commit 537a648

Browse files
authored
fix(codewhisperer): Show re-auth prompt when invoking Cwspr APIs while connection expires (#3722)
* Show re-authenticate prompt when invoking CodeWhisperer APIs while connection expired * improve code format * improve readability
1 parent b694273 commit 537a648

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Show re-authenticate prompt when invoking CodeWhisperer APIs while connection expired"
4+
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/startup/CodeWhispererProjectStartupActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CodeWhispererProjectStartupActivity : StartupActivity.DumbAware {
4141
if (runOnce) return
4242

4343
// Reconnect CodeWhisperer on startup
44-
promptReAuth(project)
44+
promptReAuth(project, isPluginStarting = true)
4545

4646
// install intellsense autotrigger listener, this only need to be executed 1 time
4747
project.messageBus.connect().subscribe(LookupManagerListener.TOPIC, CodeWhispererIntelliSenseAutoTriggerListener)

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererUtil.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,21 @@ object CodeWhispererUtil {
186186
// This will be called only when there's a CW connection, but it has expired(either accessToken or refreshToken)
187187
// 1. If connection is expired, try to refresh
188188
// 2. If not able to refresh, requesting re-login by showing a notification
189-
// 3. The notification will be shown at most once per IDE session
189+
// 3. The notification will be shown
190+
// 3.1 At most once per IDE restarts.
191+
// 3.2 At most once after IDE restarts,
192+
// for example, when user performs security scan or fetch code completion for the first time
190193
// Return true if need to re-auth, false otherwise
191-
fun promptReAuth(project: Project): Boolean {
194+
fun promptReAuth(project: Project, isPluginStarting: Boolean = false): Boolean {
192195
if (CodeWhispererService.hasReAuthPromptBeenShown()) return false
193196
if (!isCodeWhispererExpired(project)) return false
194197
val tokenProvider = tokenProvider(project) ?: return false
195198
return maybeReauthProviderIfNeeded(project, tokenProvider) {
196199
runInEdt {
197200
notifyConnectionExpiredRequestReauth(project)
198-
CodeWhispererService.markReAuthPromptShown()
201+
if (!isPluginStarting) {
202+
CodeWhispererService.markReAuthPromptShown()
203+
}
199204
}
200205
}
201206
}

0 commit comments

Comments
 (0)