Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
3010f10e
Unverified
Commit
3010f10e
authored
Mar 05, 2026
by
Peter Etelej
Committed by
GitHub
Mar 05, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: access token refresh on web app (#5681)
parent
334dfef7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
6 deletions
+11
-6
connect.ts
web/src/connect.ts
+8
-2
useTokenRefreshOnFocus.ts
web/src/hooks/useTokenRefreshOnFocus.ts
+3
-4
No files found.
web/src/connect.ts
View file @
3010f10e
import
{
timestampDate
}
from
"@bufbuild/protobuf/wkt"
;
import
{
Code
,
ConnectError
,
createClient
,
type
Interceptor
}
from
"@connectrpc/connect"
;
import
{
createConnectTransport
}
from
"@connectrpc/connect-web"
;
import
{
getAccessToken
,
isTokenExpired
,
REQUEST_TOKEN_EXPIRY_BUFFER_MS
,
setAccessToken
}
from
"./auth-state"
;
import
{
getAccessToken
,
hasStoredToken
,
isTokenExpired
,
REQUEST_TOKEN_EXPIRY_BUFFER_MS
,
setAccessToken
}
from
"./auth-state"
;
import
{
ActivityService
}
from
"./types/proto/api/v1/activity_service_pb"
;
import
{
AttachmentService
}
from
"./types/proto/api/v1/attachment_service_pb"
;
import
{
AuthService
}
from
"./types/proto/api/v1/auth_service_pb"
;
...
...
@@ -124,7 +124,13 @@ async function refreshAndGetAccessToken(): Promise<string> {
async
function
getRequestToken
():
Promise
<
string
|
null
>
{
let
token
=
getAccessToken
();
if
(
!
token
)
{
return
null
;
if
(
!
hasStoredToken
())
return
null
;
try
{
token
=
await
refreshAndGetAccessToken
();
}
catch
{
return
null
;
}
return
token
;
}
// Preflight refresh: avoid sending requests with expired access tokens.
...
...
web/src/hooks/useTokenRefreshOnFocus.ts
View file @
3010f10e
import
{
useEffect
}
from
"react"
;
import
{
FOCUS_TOKEN_EXPIRY_BUFFER_MS
,
getAccess
Token
,
isTokenExpired
}
from
"@/auth-state"
;
import
{
FOCUS_TOKEN_EXPIRY_BUFFER_MS
,
hasStored
Token
,
isTokenExpired
}
from
"@/auth-state"
;
/**
* Hook that proactively refreshes the access token when the tab becomes visible
...
...
@@ -20,9 +20,8 @@ export function useTokenRefreshOnFocus(refreshFn: () => Promise<void>, enabled:
return
;
}
// Only refresh if we have a token
const
token
=
getAccessToken
();
if
(
!
token
)
{
// Only refresh if the user has logged in before (token in localStorage)
if
(
!
hasStoredToken
())
{
return
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment