Skip to content

Instantly share code, notes, and snippets.

@aubryll
Created August 2, 2020 08:45
Show Gist options
  • Save aubryll/6d8a48f1b75b63a4be7c4cc369a1f3f3 to your computer and use it in GitHub Desktop.
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
<PrivateRoute exact path="/props-through-render" render={(props) => <PropsPage {...props} title={`Props through render`} />} />
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