Created
August 2, 2020 08:45
-
-
Save aubryll/6d8a48f1b75b63a4be7c4cc369a1f3f3 to your computer and use it in GitHub Desktop.
Keycloak react private route that accepts a route with params, possible answer to this question https://github.com/the-glue/react-router-keycloak/issues/7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<PrivateRoute exact path="/props-through-render" render={(props) => <PropsPage {...props} title={`Props through render`} />} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Route } from 'react-router-dom'; | |
import { withKeycloak } from '@react-keycloak/web' | |
function PrivateRoute({ ...rest }) { | |
return rest.keycloakInitialized && <Route {...rest} render={props => ( | |
rest.keycloak.authenticated ? rest.render(props) : rest.keycloak.login() | |
)} /> | |
} | |
export default withKeycloak(PrivateRoute) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment