From 5c1123a2e1622c61402dec788898a0cd15723368 Mon Sep 17 00:00:00 2001 From: Aleksandr Gavrilov Date: Sun, 12 Nov 2017 21:40:24 +0300 Subject: [PATCH 1/3] fix firebase config --- src/config.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/config.js b/src/config.js index 2782a0b..5c9f8f6 100644 --- a/src/config.js +++ b/src/config.js @@ -1,12 +1,13 @@ import firebase from 'firebase' export const appName = 'advreact-1610' +const appId = 'ec352' firebase.initializeApp({ - apiKey: "AIzaSyB31xpTtp4Jln_hb2kAbE4PGf6Mi8EgLyA", - authDomain: `${appName}.firebaseapp.com`, - databaseURL: `https://${appName}.firebaseio.com`, - projectId: appName, - storageBucket: "", - messagingSenderId: "397157634637" -}) \ No newline at end of file + apiKey: "AIzaSyB3LVTO7RSDrZAkHBkpzg9T5KkuoCoy4qo", + authDomain: `${appName}-${appId}.firebaseapp.com`, + databaseURL: `https://${appName}-${appId}.firebaseio.com`, + projectId: `${appName}-${appId}`, + storageBucket: `${appName}-${appId}.appspot.com`, + messagingSenderId: "651090769196" +}) From 60fb9f2e3f25839424ad3bee3e67cd62971ab72d Mon Sep 17 00:00:00 2001 From: Aleksandr Gavrilov Date: Mon, 13 Nov 2017 00:07:07 +0300 Subject: [PATCH 2/3] cancel people sync saga --- src/ducks/people.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ducks/people.js b/src/ducks/people.js index 509323e..df298aa 100644 --- a/src/ducks/people.js +++ b/src/ducks/people.js @@ -6,6 +6,7 @@ import {delay, eventChannel} from 'redux-saga' import firebase from 'firebase' import {createSelector} from 'reselect' import {fbToEntities} from './utils' +import {LOCATION_CHANGE} from 'react-router-redux' /** * Constants @@ -193,11 +194,19 @@ export const realtimePeopleSyncSaga = function * () { } } +export const cancelRealtimePeopleSyncSaga = function * (action) { + if (action && action.payload && action.payload.pathname !== '/people') { + const watcher = yield fork(realtimePeopleSyncSaga); + yield cancel(watcher); + } +} + export function * saga() { yield spawn(realtimePeopleSyncSaga) yield all([ takeEvery(ADD_PERSON_REQUEST, addPersonSaga), - takeEvery(ADD_EVENT_REQUEST, addEventToPersonSaga) + takeEvery(ADD_EVENT_REQUEST, addEventToPersonSaga), + takeEvery(LOCATION_CHANGE, cancelRealtimePeopleSyncSaga) ]) } \ No newline at end of file From c6b2464ae06fee7b2b514e90441a4f2b691a59ca Mon Sep 17 00:00:00 2001 From: Aleksandr Gavrilov Date: Mon, 13 Nov 2017 01:44:02 +0300 Subject: [PATCH 3/3] add uth chanel --- src/ducks/auth.js | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/ducks/auth.js b/src/ducks/auth.js index 09ebeda..8614d59 100644 --- a/src/ducks/auth.js +++ b/src/ducks/auth.js @@ -2,8 +2,9 @@ import {appName} from '../config' import {Record} from 'immutable' import firebase from 'firebase' import {createSelector} from 'reselect' -import {call, put, all, take} from 'redux-saga/effects' +import {call, put, all, take, spawn} from 'redux-saga/effects' import {replace} from 'react-router-redux' +import {eventChannel} from 'redux-saga' /** * Constants @@ -69,14 +70,14 @@ export function signIn(email, password) { } } -firebase.auth().onAuthStateChanged(user => { - if (!user) return +// firebase.auth().onAuthStateChanged(user => { +// if (!user) return - window.store.dispatch({ - type: SIGN_IN_SUCCESS, - payload: { user } - }) -}) +// window.store.dispatch({ +// type: SIGN_IN_SUCCESS, +// payload: { user } +// }) +// }) /** * Sagas @@ -134,7 +135,33 @@ export function * watchStatusChangeSaga() { } } +const createAuthSocket = () => eventChannel(emit => { + const authChannel = eventChannel(emit => { + const unsubscribe = firebase.auth().onAuthStateChanged( + user => emit({ user }), + error => emit({ error }) + ) + + return unsubscribe; + }); +}) + +export const realtimeAuthSaga = function * () { + const task = yield call(createAuthSocket) + + while (true) { + const { user } = yield take(createAuthSocket) + + yield put({ + type: SIGN_IN_SUCCESS, + payload: { user } + }) + } +} + export function * saga() { + yield spawn(realtimeAuthSaga) + yield all([ signUpSaga(), signInSaga(),