client/src/sagas/index.js
changeset 55 a2761c5be551
parent 54 fad489be9c77
child 56 96543c395baa
--- a/client/src/sagas/index.js	Mon Jun 19 17:30:03 2017 +0200
+++ b/client/src/sagas/index.js	Mon Jun 19 17:56:43 2017 +0200
@@ -3,8 +3,6 @@
 import * as types from '../constants/actionTypes';
 import PouchDBFind from 'pouchdb-find';
 import Immutable from 'immutable';
-import APIClient from '../APIClient';
-import config from '../config';
 
 PouchDB.debug.disable();
 PouchDB.plugin(PouchDBFind);
@@ -15,8 +13,6 @@
   index: { fields: ['session'] }
 });
 
-const client = new APIClient(config.apiRootUrl);
-
 // ---
 
 export function* loadSessions() {
@@ -99,11 +95,12 @@
   }
 }
 
-function* watchLoginRequest() {
+function* watchLoginRequest(context) {
   while (true) {
     try {
 
         const { username, password } = yield take(types.AUTH_LOGIN_REQUEST);
+        const client = context['client'];
         const response = yield client.post('/api/auth/login/', { username, password });
 
         localStorage.setItem('currentUser', JSON.stringify(response.user));
@@ -156,7 +153,7 @@
 
 // ---
 
-export default function* rootSaga() {
+export default function* rootSaga(context) {
   yield all([
     watchLoadSessions(),
     watchLoadNotesBySession(),
@@ -164,7 +161,7 @@
     watchCreateSession(),
     watchUpdateSession(),
     watchLoginSubmit(),
-    watchLoginRequest(),
+    watchLoginRequest(context),
     watchStoreToken(),
     watchUpdateSettings(),
   ])