Skip to content
François Gérard edited this page Sep 6, 2019 · 3 revisions

Usage of authenticated APIs

import {whoamiV1} from 'ps-web-apis'

whoamiV1().then(whoami => {
   if (whoami.isLoggedId()) {
     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')
});

Clone this wiki locally