Last active
August 28, 2018 08:02
-
-
Save eyeccc/9992d56f459a913b58f44ac76d0fee50 to your computer and use it in GitHub Desktop.
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
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