SHARE
TWEET

Untitled

a guest Jun 18th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const authorizeEpic: Epic<ActionTypes, ActionTypes, RootState> = action$ =>
  2.   action$.pipe(
  3.     filter(isActionOf(actions.attemptLogin.request)),
  4.     switchMap(async val => {
  5.       if (!val.payload) {
  6.         try {
  7.           const token: Auth.Token = JSON.parse(
  8.             localStorage.getItem(LOCAL_STORAGE_KEY) || ""
  9.           );
  10.           if (!token) {
  11.             throw new Error();
  12.           }
  13.           return actions.attemptLogin.success({
  14.             token
  15.           });
  16.         } catch (e) {
  17.           return actions.attemptLogin.failure({
  18.             error: {
  19.               title: "Unable to decode JWT"
  20.             }
  21.           });
  22.         }
  23.       }
  24.  
  25.       const resp = await Auth.passwordGrant(
  26.         {
  27.           email: val.payload.email,
  28.           password: val.payload.password,
  29.           totp_passcode: ""
  30.         },
  31.         {
  32.           url: "localhost:8088",
  33.           noVersion: true,
  34.           useHttp: true
  35.         }
  36.       );
  37.  
  38.       if (resp.ok) {
  39.         return [
  40.           actions.attemptLogin.success({
  41.             token: resp.value
  42.           })
  43.           // EMIT action 2, etc...
  44.         ];
  45.       }
  46.  
  47.       return actions.attemptLogin.failure(resp);
  48.     })
  49.   );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top