Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const authorizeEpic: Epic<ActionTypes, ActionTypes, RootState> = action$ =>
- action$.pipe(
- filter(isActionOf(actions.attemptLogin.request)),
- switchMap(async val => {
- if (!val.payload) {
- try {
- const token: Auth.Token = JSON.parse(
- localStorage.getItem(LOCAL_STORAGE_KEY) || ""
- );
- if (!token) {
- throw new Error();
- }
- return actions.attemptLogin.success({
- token
- });
- } catch (e) {
- return actions.attemptLogin.failure({
- error: {
- title: "Unable to decode JWT"
- }
- });
- }
- }
- const resp = await Auth.passwordGrant(
- {
- email: val.payload.email,
- password: val.payload.password,
- totp_passcode: ""
- },
- {
- url: "localhost:8088",
- noVersion: true,
- useHttp: true
- }
- );
- if (resp.ok) {
- return [
- actions.attemptLogin.success({
- token: resp.value
- })
- // EMIT action 2, etc...
- ];
- }
- return actions.attemptLogin.failure(resp);
- })
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement