Skip to content

Instantly share code, notes, and snippets.

@eyeccc
Last active August 28, 2018 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyeccc/9992d56f459a913b58f44ac76d0fee50 to your computer and use it in GitHub Desktop.
Save eyeccc/9992d56f459a913b58f44ac76d0fee50 to your computer and use it in GitHub Desktop.
type state = {
isAuthed: bool
};
type action = | SetAuthenticated(bool);
let component = ReasonReact.reducerComponent("KeycloakApp");
let make = (_children) => {
...component,
initialState: () => {isAuthed: false},
reducer: (action, _state) =>
switch action {
| SetAuthenticated(isAuthed) => ReasonReact.Update({isAuthed})
},
didMount: ({send}) =>
Keycloak.auth
|> Js.Promise.then_(
(authenticated) => {
authenticated |. SetAuthenticated |> send;
Js.Promise.resolve()
}
)
|> ignore,
render: ({state}) =>
switch state.isAuthed {
| false => <div> ("You're not authorized." |> ReasonReact.str) </div>
| true => <MySecuredApp />
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment