@@ -232,13 +232,7 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
232
232
return optionalWrite (http .StatusUnauthorized , resp )
233
233
}
234
234
235
- var (
236
- link database.UserLink
237
- now = dbtime .Now ()
238
- // Tracks if the API key has properties updated
239
- changed = false
240
- )
241
-
235
+ now := dbtime .Now ()
242
236
if key .ExpiresAt .Before (now ) {
243
237
return optionalWrite (http .StatusUnauthorized , codersdk.Response {
244
238
Message : SignedOutErrorMessage ,
@@ -252,7 +246,7 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
252
246
if key .LoginType == database .LoginTypeGithub || key .LoginType == database .LoginTypeOIDC {
253
247
var err error
254
248
//nolint:gocritic // System needs to fetch UserLink to check if it's valid.
255
- link , err = cfg .DB .GetUserLinkByUserIDLoginType (dbauthz .AsSystemRestricted (ctx ), database.GetUserLinkByUserIDLoginTypeParams {
249
+ link , err : = cfg .DB .GetUserLinkByUserIDLoginType (dbauthz .AsSystemRestricted (ctx ), database.GetUserLinkByUserIDLoginTypeParams {
256
250
UserID : key .UserID ,
257
251
LoginType : key .LoginType ,
258
252
})
@@ -309,7 +303,7 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
309
303
if link .OAuthRefreshToken == "" {
310
304
return optionalWrite (http .StatusUnauthorized , codersdk.Response {
311
305
Message : SignedOutErrorMessage ,
312
- Detail : fmt .Sprintf ("%s session expired at %q." , friendlyName , link .OAuthExpiry .String ()),
306
+ Detail : fmt .Sprintf ("%s session expired at %q. Try signing in again. " , friendlyName , link .OAuthExpiry .String ()),
313
307
})
314
308
}
315
309
// We have a refresh token, so let's try it
@@ -351,6 +345,9 @@ func ExtractAPIKey(rw http.ResponseWriter, r *http.Request, cfg ExtractAPIKeyCon
351
345
}
352
346
}
353
347
348
+ // Tracks if the API key has properties updated
349
+ changed := false
350
+
354
351
// Only update LastUsed once an hour to prevent database spam.
355
352
if now .Sub (key .LastUsed ) > time .Hour {
356
353
key .LastUsed = now
0 commit comments