fix state management
This commit is contained in:
parent
128a2a8f75
commit
57bc091499
14
app/package-lock.json
generated
14
app/package-lock.json
generated
|
@ -9,7 +9,7 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@authorizerdev/authorizer-react": "0.7.0",
|
"@authorizerdev/authorizer-react": "0.8.0",
|
||||||
"@types/react": "^17.0.15",
|
"@types/react": "^17.0.15",
|
||||||
"@types/react-dom": "^17.0.9",
|
"@types/react-dom": "^17.0.9",
|
||||||
"esbuild": "^0.12.17",
|
"esbuild": "^0.12.17",
|
||||||
|
@ -35,9 +35,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@authorizerdev/authorizer-react": {
|
"node_modules/@authorizerdev/authorizer-react": {
|
||||||
"version": "0.7.0",
|
"version": "0.8.0",
|
||||||
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-0.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-0.8.0.tgz",
|
||||||
"integrity": "sha512-cAxUhodftIveSQt+rFuEA0CxjmbpVfE43ioZBwBxqWEuJHPdPH7bohOQRgTyA2xb3QVnh7kr607Tau13DO7qUA==",
|
"integrity": "sha512-178XWGEPsovy3f6Yi2Llh6kFmjdf3ZrkIsqIAKEGPhZawV/1sA6v+4FZp7ReuCxsCelckFFQUnPR8P7od+2HeA==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@authorizerdev/authorizer-js": "^0.3.0",
|
"@authorizerdev/authorizer-js": "^0.3.0",
|
||||||
"final-form": "^4.20.2",
|
"final-form": "^4.20.2",
|
||||||
|
@ -837,9 +837,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@authorizerdev/authorizer-react": {
|
"@authorizerdev/authorizer-react": {
|
||||||
"version": "0.7.0",
|
"version": "0.8.0",
|
||||||
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-0.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/@authorizerdev/authorizer-react/-/authorizer-react-0.8.0.tgz",
|
||||||
"integrity": "sha512-cAxUhodftIveSQt+rFuEA0CxjmbpVfE43ioZBwBxqWEuJHPdPH7bohOQRgTyA2xb3QVnh7kr607Tau13DO7qUA==",
|
"integrity": "sha512-178XWGEPsovy3f6Yi2Llh6kFmjdf3ZrkIsqIAKEGPhZawV/1sA6v+4FZp7ReuCxsCelckFFQUnPR8P7od+2HeA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@authorizerdev/authorizer-js": "^0.3.0",
|
"@authorizerdev/authorizer-js": "^0.3.0",
|
||||||
"final-form": "^4.20.2",
|
"final-form": "^4.20.2",
|
||||||
|
|
|
@ -6,6 +6,9 @@ import Root from './Root';
|
||||||
export default function App() {
|
export default function App() {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const globalState: Record<string, string> = window['__authorizer__'];
|
const globalState: Record<string, string> = window['__authorizer__'];
|
||||||
|
if (globalState.state) {
|
||||||
|
sessionStorage.setItem('authorizer_state', globalState.state);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
|
|
@ -11,9 +11,14 @@ export default function Root() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (token) {
|
if (token) {
|
||||||
|
const state = sessionStorage.getItem('authorizer_state')?.trim();
|
||||||
const url = new URL(config.redirectURL || '/app');
|
const url = new URL(config.redirectURL || '/app');
|
||||||
if (url.origin !== window.location.origin) {
|
if (url.origin !== window.location.origin) {
|
||||||
window.location.href = config.redirectURL || '/app';
|
console.log({ x: `${config.redirectURL || '/app'}?state=${state}` });
|
||||||
|
sessionStorage.removeItem('authorizer_state');
|
||||||
|
window.location.replace(
|
||||||
|
`${config.redirectURL || '/app'}?state=${state}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return () => {};
|
return () => {};
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
type State struct {
|
type State struct {
|
||||||
AuthorizerURL string `json:"authorizerURL"`
|
AuthorizerURL string `json:"authorizerURL"`
|
||||||
RedirectURL string `json:"redirectURL"`
|
RedirectURL string `json:"redirectURL"`
|
||||||
|
State string `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppHandler is the handler for the /app route
|
// AppHandler is the handler for the /app route
|
||||||
|
@ -80,6 +81,7 @@ func AppHandler() gin.HandlerFunc {
|
||||||
"data": map[string]string{
|
"data": map[string]string{
|
||||||
"authorizerURL": stateObj.AuthorizerURL,
|
"authorizerURL": stateObj.AuthorizerURL,
|
||||||
"redirectURL": stateObj.RedirectURL,
|
"redirectURL": stateObj.RedirectURL,
|
||||||
|
"state": stateObj.State,
|
||||||
"organizationName": envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyOrganizationName),
|
"organizationName": envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyOrganizationName),
|
||||||
"organizationLogo": envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyOrganizationLogo),
|
"organizationLogo": envstore.EnvStoreObj.GetStringStoreEnvVariable(constants.EnvKeyOrganizationLogo),
|
||||||
},
|
},
|
||||||
|
|
|
@ -51,7 +51,7 @@ func AuthorizeHandler() gin.HandlerFunc {
|
||||||
isQuery := responseMode == "query"
|
isQuery := responseMode == "query"
|
||||||
|
|
||||||
hostname := utils.GetHost(gc)
|
hostname := utils.GetHost(gc)
|
||||||
loginRedirectState := crypto.EncryptB64(`{"authorizerURL":"` + hostname + `","redirectURL":"` + redirectURI + `"}`)
|
loginRedirectState := crypto.EncryptB64(`{"authorizerURL":"` + hostname + `","redirectURL":"` + redirectURI + `", "state":"` + state + `"}`)
|
||||||
loginURL := "/app?state=" + loginRedirectState
|
loginURL := "/app?state=" + loginRedirectState
|
||||||
|
|
||||||
if clientID == "" {
|
if clientID == "" {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user