generator-jhipster: Login redirect doesn't work in OAuth2 and React
Overview of the issue
Opening a non-public URL (which requires a authenticated user) doesn’t work as expected and the following error is thrown:
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
in Lifecycle (created by Context.Consumer)
in Redirect (created by Context.Consumer)
in Route (created by PrivateRouteComponent)
in PrivateRouteComponent (created by Connect(PrivateRouteComponent))
in Connect(PrivateRouteComponent) (created by Routes)
in Switch (created by Routes)
in div (created by Routes)
in Routes (created by App)
in ErrorBoundary (created by App)
in div (created by Card)
in Card (created by App)
in div (created by App)
in div (created by App)
in Router (created by BrowserRouter)
in BrowserRouter (created by App)
in App (created by HotExportedApp)
in AppContainer (created by HotExportedApp)
in HotExportedApp (created by ConnectFunction)
in ConnectFunction
in div
in Provider
in ErrorBoundary
This problem is not present when choosing Angular with OAuth, or using React with JWT. The combination of React with OAuth has this issue.
Motivation for or Use Case
Users want to be redirected to the requested page after they logged in Keycloak. In our case, we send emails to users to review some information what requires authentication and then redirect to that specific page.
Reproduce the error
- Create a new Monolithic application and choose OAuth 2.0 and React
- Start container for Keycloak
- Run the application
- Without signing in, open a non-public URL like http://localhost:9000/admin/audits
- Error message appears. Keycloak page to login is expected.
Related issues
n/a
Suggest a Fix
n/a
JHipster Version(s)
6.10.5
JHipster configuration
jhipster info
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:info
Welcome to the JHipster Information Sub-Generator
##### **JHipster Version(s)**
tms@0.0.1-SNAPSHOT /mnt/myfiles/Projects/tmp/redirect-oidc-test
└── generator-jhipster@6.10.5
##### **JHipster configuration, a `.yo-rc.json` file generated in the root folder**
<details>
<summary>.yo-rc.json file</summary>
<pre>
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.andespetro.tms"
},
"jhipsterVersion": "6.10.5",
"applicationType": "monolith",
"baseName": "tms",
"packageName": "com.andespetro.tms",
"packageFolder": "com/andespetro/tms",
"serverPort": "8080",
"authenticationType": "oauth2",
"cacheProvider": "ehcache",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "postgresql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"embeddableLaunchScript": false,
"useSass": true,
"clientPackageManager": "npm",
"clientFramework": "react",
"clientTheme": "none",
"clientThemeVariant": "",
"creationTimestamp": 1604848055606,
"testFrameworks": [],
"jhiPrefix": "jhi",
"entitySuffix": "",
"dtoSuffix": "DTO",
"otherModules": [],
"enableTranslation": false,
"blueprints": []
}
}
</pre>
</details>
##### **JDL for the Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**
<details>
<summary>JDL entity definitions</summary>
<pre>
</pre>
</details>
##### **Environment and Tools**
openjdk version "11.0.9" 2020-10-20
OpenJDK Runtime Environment 18.9 (build 11.0.9+11)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.9+11, mixed mode, sharing)
git version 2.26.2
node: v12.19.0
npm: 6.14.8
yeoman: 3.1.1
yarn: 1.21.1
INFO! Congratulations, JHipster execution is complete!
.yo-rc.json
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.andespetro.tms"
},
"jhipsterVersion": "6.10.5",
"applicationType": "monolith",
"baseName": "tms",
"packageName": "com.andespetro.tms",
"packageFolder": "com/andespetro/tms",
"serverPort": "8080",
"authenticationType": "oauth2",
"cacheProvider": "ehcache",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "postgresql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"embeddableLaunchScript": false,
"useSass": true,
"clientPackageManager": "npm",
"clientFramework": "react",
"clientTheme": "none",
"clientThemeVariant": "",
"creationTimestamp": 1604848055606,
"testFrameworks": [],
"jhiPrefix": "jhi",
"entitySuffix": "",
"dtoSuffix": "DTO",
"otherModules": [],
"enableTranslation": false,
"blueprints": []
}
}
Entity configuration(s) entityName.json files generated in the .jhipster directory
Error is not related to entity creation.
Browsers and Operating System
OS: Fedora 32 Browsers: Firefox 82.0.2 and Chrome 86.0.4240.183
- [x ] Checking this box is mandatory (this is just to show you read everything)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (14 by maintainers)
@qmonmert I tried your branch and it does work. However, it doesn’t redirect me back to my original URL (e.g.,
http://localhost:8080/admin/health). Not sure if it’s possible to fix that.