Hi all
On the top of a file, I’ve following definition:
%raw "import Keycloak from 'keycloak-js'";
%raw "const keycloak = Keycloak('config/keycloak.json')";
and this is, how I am using the object keycloak
let authorize: unit => Js.Promise.t(string) = () => [%raw {|
new Promise((resolve, reject) => {
keycloak
.init({
onLoad: 'login-required'
})
.success(authenticated => {
if (authenticated) {
resolve('You are authenticated.');
} else {
reject('You are not authenticated');
}
})
.error(function() {
reject('Failed to initialize');
});
})
|}];
Would you do like I’ve done above, or use @bs annotation?
Or more example:
let authenticated: bool = [%raw "keycloak.authenticated"];
if (!authenticated) {
reject(. Js.Exn.raiseError("Your are not authorized!"));
} else {
let token: string = [%raw "keycloak.token"];
let subject: string = [%raw "keycloak.subject"];
let idToken: string = [%raw "keycloak.idToken"];
this
let token: string = [%raw "keycloak.token"];
I do not like. How to write it better with @bs.value
?
Thanks