Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cf2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vojtech.pikal
cf2021
Commits
5147b735
Commit
5147b735
authored
4 years ago
by
xaralis
Browse files
Options
Downloads
Patches
Plain Diff
fix: app not realising refresh token has expired
parent
9281cde8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/App.jsx
+8
-2
8 additions, 2 deletions
src/App.jsx
src/actions/users.js
+29
-1
29 additions, 1 deletion
src/actions/users.js
src/index.js
+10
-0
10 additions, 0 deletions
src/index.js
with
47 additions
and
3 deletions
src/App.jsx
+
8
−
2
View file @
5147b735
...
...
@@ -11,7 +11,7 @@ import { loadAnnouncements } from "actions/announcements";
import
{
loadConfig
}
from
"
actions/global-info
"
;
import
{
loadPosts
}
from
"
actions/posts
"
;
import
{
loadProgram
}
from
"
actions/program
"
;
import
{
loadMe
}
from
"
actions/users
"
;
import
{
loadMe
,
refreshAccessToken
}
from
"
actions/users
"
;
import
{
initializeWSChannel
}
from
"
actions/ws
"
;
import
Footer
from
"
components/Footer
"
;
import
Navbar
from
"
components/Navbar
"
;
...
...
@@ -39,7 +39,12 @@ if (process.env.REACT_APP_SENTRY_DSN) {
const
ReactHint
=
ReactHintFactory
(
React
);
const
onKeycloakEvent
=
(
event
)
=>
{
const
onKeycloakEvent
=
async
(
event
)
=>
{
if
(
event
===
"
onTokenExpired
"
)
{
console
.
warn
(
"
[auth] access token expired, attempting refresh
"
);
refreshAccessToken
();
}
if
([
"
onAuthRefreshSuccess
"
,
"
onAuthSuccess
"
].
includes
(
event
))
{
Sentry
.
setUser
(
keycloak
.
tokenParsed
);
...
...
@@ -154,6 +159,7 @@ const AuthenticatedApp = () => {
initConfig
=
{
keycloakInitConfig
}
LoadingComponent
=
{
LoadingComponent
}
onEvent
=
{
onKeycloakEvent
}
autoRefreshToken
=
{
false
}
>
<
Suspense
fallback
=
{
LoadingComponent
}
>
<
ConfiguredApp
/>
...
...
This diff is collapsed.
Click to expand it.
src/actions/users.js
+
29
−
1
View file @
5147b735
import
*
as
Sentry
from
"
@sentry/react
"
;
import
{
createAsyncAction
,
errorResult
,
successResult
}
from
"
pullstate
"
;
import
{
fetch
}
from
"
api
"
;
import
{
AuthStore
}
from
"
stores
"
;
import
keycloak
from
"
keycloak
"
;
import
{
AuthStore
,
PostStore
}
from
"
stores
"
;
import
{
updateWindowPosts
}
from
"
utils
"
;
export
const
loadMe
=
createAsyncAction
(
/**
...
...
@@ -89,3 +92,28 @@ export const inviteToJitsi = createAsyncAction(
}
}
);
export
const
refreshAccessToken
=
async
()
=>
{
try
{
await
keycloak
.
updateToken
(
300
);
console
.
info
(
"
[auth] access token refreshed
"
);
}
catch
(
exc
)
{
console
.
warn
(
"
[auth] could not refresh the access token, refresh token possibly expired, logging out
"
);
Sentry
.
setUser
(
null
);
AuthStore
.
update
((
state
)
=>
{
state
.
isAuthenticated
=
false
;
state
.
user
=
null
;
state
.
showJitsiInvitePopup
=
false
;
state
.
jitsiPopupDimissed
=
false
;
});
PostStore
.
update
((
state
)
=>
{
state
.
filters
.
showPendingProposals
=
false
;
updateWindowPosts
(
state
);
});
}
};
This diff is collapsed.
Click to expand it.
src/index.js
+
10
−
0
View file @
5147b735
...
...
@@ -2,11 +2,21 @@ import React from "react";
import
ReactDOM
from
"
react-dom
"
;
import
ReactModal
from
"
react-modal
"
;
import
{
refreshAccessToken
}
from
"
actions/users
"
;
import
App
from
"
./App
"
;
import
*
as
serviceWorker
from
"
./serviceWorker
"
;
const
root
=
document
.
getElementById
(
"
root
"
);
function
handleVisibilityChange
()
{
if
(
!
document
.
hidden
)
{
refreshAccessToken
();
}
}
document
.
addEventListener
(
"
visibilitychange
"
,
handleVisibilityChange
,
false
);
ReactDOM
.
render
(
<
React
.
StrictMode
>
<
App
/>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment