Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Gets the repositories of the user from Github
- */
- import { Redirect } from 'react-router';
- import { take, call, put, select, cancel, takeLatest } from 'redux-saga/effects';
- import { GET_TOKEN } from './constants';
- import { getTokenSuccess, getTokenError } from './actions';
- import { changeIsLoading } from './actions';
- import {
- makeSelectUsername,
- makeSelectPassword,
- makeSelectConnection,
- } from './selectors';
- import { storeToken, storeProvider } from '../User/lib';
- import { setUser } from 'containers/User/actions';
- import { push } from 'react-router-redux';
- import request from 'utils/request';
- import Amplify, { Auth } from 'aws-amplify';
- Amplify.configure({
- Auth: {
- // REQUIRED - Amazon Cognito Identity Pool ID
- identityPoolId: 'ap-southeast-2:8e4396d2-5fec-40a4-9597-43c94a3d0692',
- // REQUIRED - Amazon Cognito Region
- region: 'ap-southeast-2',
- // OPTIONAL - Amazon Cognito User Pool ID
- userPoolId: 'ap-southeast-2_tEoUdRL5E',
- // OPTIONAL - Amazon Cognito Web Client ID
- userPoolWebClientId: '13agbv3ghnngpn8uskvluqh8o8',
- }
- });
- /**
- * Get a token from AWS Cognito
- */
- export function* sendAWSLogin() {
- // Select username from store
- const username = yield select(makeSelectUsername());
- const password = yield select(makeSelectPassword());
- try {
- const data = yield call(authLogin, username, password);
- const token = data.signInUserSession.accessToken.jwtToken;
- yield put(getTokenSuccess(token));
- yield call(storeToken, token);
- storeProvider('Cognito');
- yield put(push('/'));
- } catch (err) {
- yield put(getTokenError(err));
- alert(err);
- }
- }
- async function authLogin(username, password, email, given_name, family_name) {
- return Auth.signIn(username, password);
- }
- /**
- * Root saga manages watcher lifecycle
- */
- export default function* getUserToken() {
- // Watches for LOAD_REPOS actions and calls getRepos when one comes in.
- // By using `takeLatest` only the result of the latest API call is applied.
- // It returns task descriptor (just like fork) so we can continue execution
- // It will be cancelled automatically on component unmount
- yield takeLatest(GET_TOKEN, sendAWSLogin);
- }
Add Comment
Please, Sign In to add comment