Guest User

Untitled

a guest
Mar 3rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. /**
  2. * Gets the repositories of the user from Github
  3. */
  4.  
  5. import { Redirect } from 'react-router';
  6. import { take, call, put, select, cancel, takeLatest } from 'redux-saga/effects';
  7. import { GET_TOKEN } from './constants';
  8. import { getTokenSuccess, getTokenError } from './actions';
  9. import { changeIsLoading } from './actions';
  10. import {
  11. makeSelectUsername,
  12. makeSelectPassword,
  13. makeSelectConnection,
  14. } from './selectors';
  15. import { storeToken, storeProvider } from '../User/lib';
  16. import { setUser } from 'containers/User/actions';
  17. import { push } from 'react-router-redux';
  18. import request from 'utils/request';
  19.  
  20. import Amplify, { Auth } from 'aws-amplify';
  21.  
  22. Amplify.configure({
  23. Auth: {
  24. // REQUIRED - Amazon Cognito Identity Pool ID
  25. identityPoolId: 'ap-southeast-2:8e4396d2-5fec-40a4-9597-43c94a3d0692',
  26. // REQUIRED - Amazon Cognito Region
  27. region: 'ap-southeast-2',
  28. // OPTIONAL - Amazon Cognito User Pool ID
  29. userPoolId: 'ap-southeast-2_tEoUdRL5E',
  30. // OPTIONAL - Amazon Cognito Web Client ID
  31. userPoolWebClientId: '13agbv3ghnngpn8uskvluqh8o8',
  32. }
  33. });
  34.  
  35. /**
  36. * Get a token from AWS Cognito
  37. */
  38. export function* sendAWSLogin() {
  39. // Select username from store
  40. const username = yield select(makeSelectUsername());
  41. const password = yield select(makeSelectPassword());
  42.  
  43. try {
  44. const data = yield call(authLogin, username, password);
  45. const token = data.signInUserSession.accessToken.jwtToken;
  46. yield put(getTokenSuccess(token));
  47. yield call(storeToken, token);
  48. storeProvider('Cognito');
  49. yield put(push('/'));
  50. } catch (err) {
  51. yield put(getTokenError(err));
  52. alert(err);
  53. }
  54. }
  55.  
  56. async function authLogin(username, password, email, given_name, family_name) {
  57. return Auth.signIn(username, password);
  58. }
  59.  
  60. /**
  61. * Root saga manages watcher lifecycle
  62. */
  63. export default function* getUserToken() {
  64. // Watches for LOAD_REPOS actions and calls getRepos when one comes in.
  65. // By using `takeLatest` only the result of the latest API call is applied.
  66. // It returns task descriptor (just like fork) so we can continue execution
  67. // It will be cancelled automatically on component unmount
  68. yield takeLatest(GET_TOKEN, sendAWSLogin);
  69. }
Add Comment
Please, Sign In to add comment