-
Notifications
You must be signed in to change notification settings - Fork 0
Home
François Gérard edited this page Nov 21, 2019
·
3 revisions
This is a client api which is only usable in Client (Browser) Context
First you need to add ps-web-apis as dependency in you application Then you have to add Rosetta as PS-Script Loader in the target-web page.
<script type="text/javascript" src="https://rosetta.prod.ps.bild.de/ps-rosetta.js"></script>
Rosetta will load the newest version of the whoami implementation.
import {whoamiV1} from 'ps-web-apis'
whoamiV1().then(whoami => {
if (whoami.isLoggedIn()) {
// show user that he is logged in
// provide logout button
}
});
import {whoamiV1} from 'ps-web-apis'
whoamiV1().then(whoami => {
whoami.doLogin();
});
import {whoamiV1} from 'ps-web-apis'
whoamiV1().then(whoami => {
whoami.getUserInfo().then((userinfo) => {
// userinfo.first_name
});
});
Authorized fetch must be used to ensure, that a valid SPRINGToken is included in BE-call
import {whoamiV1} from 'ps-web-apis'
whoamiV1().then(whoami => {
if (whoami.isLoggedIn()) {
whoami.authorizedFetch(...)
.then((resp) => /*handleResp(resp)*/)
.catch(/* handle unauthorized */)
} else {
fetch(...)
.then((resp) => /*handleResp(resp)*/)
.catch(/* handle communication error*/)
} ).catch(() => {
console.error('handle unavilability of whoami api')
});