Skip to content

Instantly share code, notes, and snippets.

Created August 2, 2020 08:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
<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({ }) {
return rest.keycloakInitialized && <Route {} 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