Skip to content

Commit 57bc091

Browse files
committed
fix state management
1 parent 128a2a8 commit 57bc091

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

app/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import Root from './Root';
66
export default function App() {
77
// @ts-ignore
88
const globalState: Record<string, string> = window['__authorizer__'];
9+
if (globalState.state) {
10+
sessionStorage.setItem('authorizer_state', globalState.state);
11+
}
912
return (
1013
<div
1114
style={{

app/src/Root.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ export default function Root() {
1111

1212
useEffect(() => {
1313
if (token) {
14+
const state = sessionStorage.getItem('authorizer_state')?.trim();
1415
const url = new URL(config.redirectURL || '/app');
1516
if (url.origin !== window.location.origin) {
16-
window.location.href = config.redirectURL || '/app';
17+
console.log({ x: `${config.redirectURL || '/app'}?state=${state}` });
18+
sessionStorage.removeItem('authorizer_state');
19+
window.location.replace(
20+
`${config.redirectURL || '/app'}?state=${state}`
21+
);
1722
}
1823
}
1924
return () => {};

server/handlers/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
type State struct {
1919
AuthorizerURL string `json:"authorizerURL"`
2020
RedirectURL string `json:"redirectURL"`
21+
State string `json:"state"`
2122
}
2223

2324
// AppHandler is the handler for the /app route
@@ -80,6 +81,7 @@ func AppHandler() gin.HandlerFunc {
8081
"data": map[string]string{
8182
"authorizerURL": stateObj.AuthorizerURL,
8283
"redirectURL": stateObj.RedirectURL,
84+
"state": stateObj.State,
8385
"organizationName": envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyOrganizationName),
8486
"organizationLogo": envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyOrganizationLogo),
8587
},

server/handlers/authorize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func AuthorizeHandler() gin.HandlerFunc {
5151
isQuery := responseMode == "query"
5252

5353
hostname := utils.GetHost(gc)
54-
loginRedirectState := crypto.EncryptB64(`{"authorizerURL":"` + hostname + `","redirectURL":"` + redirectURI + `"}`)
54+
loginRedirectState := crypto.EncryptB64(`{"authorizerURL":"` + hostname + `","redirectURL":"` + redirectURI + `", "state":"` + state + `"}`)
5555
loginURL := "/app?state=" + loginRedirectState
5656

5757
if clientID == "" {

0 commit comments

Comments
 (0)