forked from lynndylanhurley/redux-auth
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
3590 lines (2846 loc) · 123 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fetch = exports.hideDestroyAccountErrorModal = exports.hideDestroyAccountSuccessModal = exports.hideUpdatePasswordErrorModal = exports.hideUpdatePasswordSuccessModal = exports.hidePasswordResetRequestErrorModal = exports.hidePasswordResetRequestSuccessModal = exports.hidePasswordResetErrorModal = exports.hideFirstTimeLoginErrorModal = exports.showPasswordResetErrorModal = exports.showFirstTimeLoginErrorModal = exports.hidePasswordResetSuccessModal = exports.hideFirstTimeLoginSuccessModal = exports.showPasswordResetSuccessModal = exports.showFirstTimeLoginSuccessModal = exports.hideEmailSignUpErrorModal = exports.hideEmailSignUpSuccessModal = exports.hideSignOutErrorModal = exports.hideSignOutSuccessModal = exports.hideOAuthSignInErrorModal = exports.hideOAuthSignInSuccessModal = exports.hideEmailSignInErrorModal = exports.hideEmailSignInSuccessModal = exports.getApiUrl = exports.verifyAuth = exports.destroyAccount = exports.updatePasswordModalFormUpdate = exports.updatePasswordModal = exports.updatePasswordFormUpdate = exports.updatePassword = exports.requestPasswordResetFormUpdate = exports.requestPasswordReset = exports.oAuthSignIn = exports.emailSignUpComplete = exports.emailSignUpFormUpdate = exports.emailSignUp = exports.signOut = exports.emailSignInFormUpdate = exports.emailSignIn = exports.authenticate = exports.configure = exports.authStateReducer = undefined;
var _configure = __webpack_require__(73);
Object.defineProperty(exports, "configure", {
enumerable: true,
get: function get() {
return _configure.configure;
}
});
var _authenticate = __webpack_require__(75);
Object.defineProperty(exports, "authenticate", {
enumerable: true,
get: function get() {
return _authenticate.authenticate;
}
});
var _emailSignIn = __webpack_require__(92);
Object.defineProperty(exports, "emailSignIn", {
enumerable: true,
get: function get() {
return _emailSignIn.emailSignIn;
}
});
Object.defineProperty(exports, "emailSignInFormUpdate", {
enumerable: true,
get: function get() {
return _emailSignIn.emailSignInFormUpdate;
}
});
var _signOut = __webpack_require__(93);
Object.defineProperty(exports, "signOut", {
enumerable: true,
get: function get() {
return _signOut.signOut;
}
});
var _emailSignUp = __webpack_require__(94);
Object.defineProperty(exports, "emailSignUp", {
enumerable: true,
get: function get() {
return _emailSignUp.emailSignUp;
}
});
Object.defineProperty(exports, "emailSignUpFormUpdate", {
enumerable: true,
get: function get() {
return _emailSignUp.emailSignUpFormUpdate;
}
});
Object.defineProperty(exports, "emailSignUpComplete", {
enumerable: true,
get: function get() {
return _emailSignUp.emailSignUpComplete;
}
});
var _oauthSignIn = __webpack_require__(95);
Object.defineProperty(exports, "oAuthSignIn", {
enumerable: true,
get: function get() {
return _oauthSignIn.oAuthSignIn;
}
});
var _requestPasswordReset = __webpack_require__(97);
Object.defineProperty(exports, "requestPasswordReset", {
enumerable: true,
get: function get() {
return _requestPasswordReset.requestPasswordReset;
}
});
Object.defineProperty(exports, "requestPasswordResetFormUpdate", {
enumerable: true,
get: function get() {
return _requestPasswordReset.requestPasswordResetFormUpdate;
}
});
var _updatePassword = __webpack_require__(98);
Object.defineProperty(exports, "updatePassword", {
enumerable: true,
get: function get() {
return _updatePassword.updatePassword;
}
});
Object.defineProperty(exports, "updatePasswordFormUpdate", {
enumerable: true,
get: function get() {
return _updatePassword.updatePasswordFormUpdate;
}
});
var _updatePasswordModal = __webpack_require__(99);
Object.defineProperty(exports, "updatePasswordModal", {
enumerable: true,
get: function get() {
return _updatePasswordModal.updatePasswordModal;
}
});
Object.defineProperty(exports, "updatePasswordModalFormUpdate", {
enumerable: true,
get: function get() {
return _updatePasswordModal.updatePasswordModalFormUpdate;
}
});
var _destroyAccount = __webpack_require__(100);
Object.defineProperty(exports, "destroyAccount", {
enumerable: true,
get: function get() {
return _destroyAccount.destroyAccount;
}
});
var _sessionStorage = __webpack_require__(81);
Object.defineProperty(exports, "getApiUrl", {
enumerable: true,
get: function get() {
return _sessionStorage.getApiUrl;
}
});
var _ui = __webpack_require__(76);
Object.defineProperty(exports, "hideEmailSignInSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hideEmailSignInSuccessModal;
}
});
Object.defineProperty(exports, "hideEmailSignInErrorModal", {
enumerable: true,
get: function get() {
return _ui.hideEmailSignInErrorModal;
}
});
Object.defineProperty(exports, "hideOAuthSignInSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hideOAuthSignInSuccessModal;
}
});
Object.defineProperty(exports, "hideOAuthSignInErrorModal", {
enumerable: true,
get: function get() {
return _ui.hideOAuthSignInErrorModal;
}
});
Object.defineProperty(exports, "hideSignOutSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hideSignOutSuccessModal;
}
});
Object.defineProperty(exports, "hideSignOutErrorModal", {
enumerable: true,
get: function get() {
return _ui.hideSignOutErrorModal;
}
});
Object.defineProperty(exports, "hideEmailSignUpSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hideEmailSignUpSuccessModal;
}
});
Object.defineProperty(exports, "hideEmailSignUpErrorModal", {
enumerable: true,
get: function get() {
return _ui.hideEmailSignUpErrorModal;
}
});
Object.defineProperty(exports, "showFirstTimeLoginSuccessModal", {
enumerable: true,
get: function get() {
return _ui.showFirstTimeLoginSuccessModal;
}
});
Object.defineProperty(exports, "showPasswordResetSuccessModal", {
enumerable: true,
get: function get() {
return _ui.showPasswordResetSuccessModal;
}
});
Object.defineProperty(exports, "hideFirstTimeLoginSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hideFirstTimeLoginSuccessModal;
}
});
Object.defineProperty(exports, "hidePasswordResetSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hidePasswordResetSuccessModal;
}
});
Object.defineProperty(exports, "showFirstTimeLoginErrorModal", {
enumerable: true,
get: function get() {
return _ui.showFirstTimeLoginErrorModal;
}
});
Object.defineProperty(exports, "showPasswordResetErrorModal", {
enumerable: true,
get: function get() {
return _ui.showPasswordResetErrorModal;
}
});
Object.defineProperty(exports, "hideFirstTimeLoginErrorModal", {
enumerable: true,
get: function get() {
return _ui.hideFirstTimeLoginErrorModal;
}
});
Object.defineProperty(exports, "hidePasswordResetErrorModal", {
enumerable: true,
get: function get() {
return _ui.hidePasswordResetErrorModal;
}
});
Object.defineProperty(exports, "hidePasswordResetRequestSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hidePasswordResetRequestSuccessModal;
}
});
Object.defineProperty(exports, "hidePasswordResetRequestErrorModal", {
enumerable: true,
get: function get() {
return _ui.hidePasswordResetRequestErrorModal;
}
});
Object.defineProperty(exports, "hideUpdatePasswordSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hideUpdatePasswordSuccessModal;
}
});
Object.defineProperty(exports, "hideUpdatePasswordErrorModal", {
enumerable: true,
get: function get() {
return _ui.hideUpdatePasswordErrorModal;
}
});
Object.defineProperty(exports, "hideDestroyAccountSuccessModal", {
enumerable: true,
get: function get() {
return _ui.hideDestroyAccountSuccessModal;
}
});
Object.defineProperty(exports, "hideDestroyAccountErrorModal", {
enumerable: true,
get: function get() {
return _ui.hideDestroyAccountErrorModal;
}
});
var _fetch = __webpack_require__(79);
Object.defineProperty(exports, "fetch", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_fetch).default;
}
});
var _authenticate2 = __webpack_require__(101);
var _authenticate3 = _interopRequireDefault(_authenticate2);
var _configure2 = __webpack_require__(103);
var _configure3 = _interopRequireDefault(_configure2);
var _user = __webpack_require__(104);
var _user2 = _interopRequireDefault(_user);
var _ui2 = __webpack_require__(105);
var _ui3 = _interopRequireDefault(_ui2);
var _emailSignIn2 = __webpack_require__(106);
var _emailSignIn3 = _interopRequireDefault(_emailSignIn2);
var _emailSignUp2 = __webpack_require__(107);
var _emailSignUp3 = _interopRequireDefault(_emailSignUp2);
var _oauthSignIn2 = __webpack_require__(108);
var _oauthSignIn3 = _interopRequireDefault(_oauthSignIn2);
var _requestPasswordReset2 = __webpack_require__(109);
var _requestPasswordReset3 = _interopRequireDefault(_requestPasswordReset2);
var _updatePassword2 = __webpack_require__(110);
var _updatePassword3 = _interopRequireDefault(_updatePassword2);
var _updatePasswordModal2 = __webpack_require__(111);
var _updatePasswordModal3 = _interopRequireDefault(_updatePasswordModal2);
var _server = __webpack_require__(112);
var _server2 = _interopRequireDefault(_server);
var _signOut2 = __webpack_require__(113);
var _signOut3 = _interopRequireDefault(_signOut2);
var _destroyAccount2 = __webpack_require__(114);
var _destroyAccount3 = _interopRequireDefault(_destroyAccount2);
var _reduxImmutablejs = __webpack_require__(102);
var _verifyAuth2 = __webpack_require__(85);
var _verifyAuth3 = _interopRequireDefault(_verifyAuth2);
var _handleFetchResponse = __webpack_require__(84);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* reducers */
var authStateReducer = exports.authStateReducer = (0, _reduxImmutablejs.combineReducers)({
configure: _configure3.default,
emailSignIn: _emailSignIn3.default,
emailSignUp: _emailSignUp3.default,
signOut: _signOut3.default,
authentication: _authenticate3.default,
requestPasswordReset: _requestPasswordReset3.default,
oAuthSignIn: _oauthSignIn3.default,
updatePassword: _updatePassword3.default,
updatePasswordModal: _updatePasswordModal3.default,
destroyAccount: _destroyAccount3.default,
server: _server2.default,
ui: _ui3.default,
user: _user2.default
});
/* actions */
exports.verifyAuth = _verifyAuth3.default;
/***/ },
/* 1 */,
/* 2 */,
/* 3 */,
/* 4 */,
/* 5 */,
/* 6 */,
/* 7 */,
/* 8 */,
/* 9 */,
/* 10 */,
/* 11 */,
/* 12 */,
/* 13 */,
/* 14 */
/***/ function(module, exports) {
module.exports = require("immutable");
/***/ },
/* 15 */,
/* 16 */,
/* 17 */,
/* 18 */,
/* 19 */,
/* 20 */,
/* 21 */,
/* 22 */,
/* 23 */,
/* 24 */,
/* 25 */,
/* 26 */,
/* 27 */,
/* 28 */,
/* 29 */,
/* 30 */,
/* 31 */,
/* 32 */,
/* 33 */,
/* 34 */,
/* 35 */,
/* 36 */,
/* 37 */,
/* 38 */,
/* 39 */,
/* 40 */,
/* 41 */,
/* 42 */,
/* 43 */,
/* 44 */,
/* 45 */,
/* 46 */,
/* 47 */,
/* 48 */,
/* 49 */,
/* 50 */,
/* 51 */,
/* 52 */,
/* 53 */,
/* 54 */,
/* 55 */,
/* 56 */,
/* 57 */,
/* 58 */,
/* 59 */,
/* 60 */,
/* 61 */,
/* 62 */,
/* 63 */,
/* 64 */
/***/ function(module, exports) {
module.exports = require("extend");
/***/ },
/* 65 */,
/* 66 */,
/* 67 */,
/* 68 */,
/* 69 */,
/* 70 */,
/* 71 */,
/* 72 */,
/* 73 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.STORE_CURRENT_ENDPOINT_KEY = exports.SET_ENDPOINT_KEYS = undefined;
exports.setEndpointKeys = setEndpointKeys;
exports.storeCurrentEndpointKey = storeCurrentEndpointKey;
exports.configure = configure;
var _extend = __webpack_require__(64);
var _extend2 = _interopRequireDefault(_extend);
var _constants = __webpack_require__(74);
var C = _interopRequireWildcard(_constants);
var _authenticate = __webpack_require__(75);
var _ui = __webpack_require__(76);
var _server = __webpack_require__(77);
var _clientSettings = __webpack_require__(78);
var _sessionStorage = __webpack_require__(81);
var _verifyAuth = __webpack_require__(85);
var _verifyAuth2 = _interopRequireDefault(_verifyAuth);
var _parseUrl = __webpack_require__(87);
var _parseUrl2 = _interopRequireDefault(_parseUrl);
var _reactRouterRedux = __webpack_require__(91);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var SET_ENDPOINT_KEYS = exports.SET_ENDPOINT_KEYS = "SET_ENDPOINT_KEYS";
var STORE_CURRENT_ENDPOINT_KEY = exports.STORE_CURRENT_ENDPOINT_KEY = "STORE_CURRENT_ENDPOINT_KEY";
function setEndpointKeys(endpoints, currentEndpointKey, defaultEndpointKey) {
return { type: SET_ENDPOINT_KEYS, endpoints: endpoints, currentEndpointKey: currentEndpointKey, defaultEndpointKey: defaultEndpointKey };
};
function storeCurrentEndpointKey(currentEndpointKey) {
return { type: STORE_CURRENT_ENDPOINT_KEY, currentEndpointKey: currentEndpointKey };
};
function configure() {
var endpoint = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var settings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return function (dispatch) {
// don't render anything for OAuth redirects
if (settings.currentLocation && settings.currentLocation.match(/blank=true/)) {
return Promise.resolve({ blank: true });
}
dispatch((0, _authenticate.authenticateStart)());
var promise = void 0,
firstTimeLogin = void 0,
mustResetPassword = void 0,
user = void 0,
headers = void 0;
if (settings.isServer) {
promise = (0, _verifyAuth2.default)(endpoint, settings).then(function (_ref) {
var user = _ref.user,
headers = _ref.headers,
firstTimeLogin = _ref.firstTimeLogin,
mustResetPassword = _ref.mustResetPassword,
currentEndpoint = _ref.currentEndpoint,
currentEndpointKey = _ref.currentEndpointKey,
defaultEndpointKey = _ref.defaultEndpointKey;
dispatch((0, _server.ssAuthTokenUpdate)({
headers: headers,
user: user,
firstTimeLogin: firstTimeLogin,
mustResetPassword: mustResetPassword
}));
dispatch(setEndpointKeys(Object.keys(currentEndpoint), currentEndpointKey, defaultEndpointKey));
return user;
}).catch(function (_ref2) {
var reason = _ref2.reason,
firstTimeLogin = _ref2.firstTimeLogin,
mustResetPassword = _ref2.mustResetPassword,
currentEndpoint = _ref2.currentEndpoint,
defaultEndpointKey = _ref2.defaultEndpointKey;
dispatch((0, _server.ssAuthTokenUpdate)({ firstTimeLogin: firstTimeLogin, mustResetPassword: mustResetPassword }));
dispatch(setEndpointKeys(Object.keys(currentEndpoint || {}), null, defaultEndpointKey));
return Promise.reject({ reason: reason });
});
} else {
// if the authentication happened server-side, find the resulting auth
// credentials that were injected into the dom.
var tokenBridge = document.getElementById("token-bridge");
var _getRedirectInfo = (0, _parseUrl2.default)(window.location),
authRedirectLocation = _getRedirectInfo.authRedirectLocation,
authRedirectHeaders = _getRedirectInfo.authRedirectHeaders;
if (tokenBridge) {
var rawServerCreds = tokenBridge.innerHTML;
if (rawServerCreds) {
var serverCreds = JSON.parse(rawServerCreds);
headers = serverCreds.headers;
user = serverCreds.user;
firstTimeLogin = serverCreds.firstTimeLogin;
mustResetPassword = serverCreds.mustResetPassword;
if (user) {
dispatch((0, _authenticate.authenticateComplete)(user));
// do NOT send initial validation request.
// instead use the credentials that were sent back by the server.
settings.initialCredentials = serverCreds;
}
// sync client dom to prevent React "out of sync" error
dispatch((0, _server.ssAuthTokenUpdate)({
user: user,
headers: headers,
mustResetPassword: mustResetPassword,
firstTimeLogin: firstTimeLogin
}));
}
} else {
mustResetPassword = authRedirectHeaders && authRedirectHeaders.reset_password;
firstTimeLogin = authRedirectHeaders && authRedirectHeaders.account_confirmation_success;
}
if (authRedirectLocation) {
dispatch((0, _reactRouterRedux.push)(authRedirectLocation));
}
if (authRedirectHeaders && authRedirectHeaders.uid && authRedirectHeaders["access-token"]) {
settings.initialCredentials = (0, _extend2.default)({}, settings.initialCredentials, { headers: authRedirectHeaders });
}
// if tokens were invalidated by server or from the settings, make sure
// to clear browser credentials
if (!settings.clientOnly && !settings.initialCredentials || settings.cleanSession) {
(0, _sessionStorage.destroySession)();
}
promise = Promise.resolve((0, _clientSettings.applyConfig)({ dispatch: dispatch, endpoint: endpoint, settings: settings }));
}
return promise.then(function (user) {
dispatch((0, _authenticate.authenticateComplete)(user));
if (firstTimeLogin) {
dispatch((0, _ui.showFirstTimeLoginSuccessModal)());
}
if (mustResetPassword) {
dispatch((0, _ui.showPasswordResetSuccessModal)());
}
return user;
}).catch(function () {
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
reason = _ref3.reason;
dispatch((0, _authenticate.authenticateError)([reason]));
if (firstTimeLogin) {
dispatch((0, _ui.showFirstTimeLoginErrorModal)());
}
if (mustResetPassword) {
dispatch((0, _ui.showPasswordResetErrorModal)());
}
return Promise.resolve({ reason: reason });
});
};
}
/***/ },
/* 74 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var INITIAL_CONFIG_KEY = exports.INITIAL_CONFIG_KEY = "default";
var DEFAULT_CONFIG_KEY = exports.DEFAULT_CONFIG_KEY = "defaultConfigKey";
var SAVED_CONFIG_KEY = exports.SAVED_CONFIG_KEY = "currentConfigName";
var SAVED_CREDS_KEY = exports.SAVED_CREDS_KEY = "authHeaders";
/***/ },
/* 75 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.authenticateStart = authenticateStart;
exports.authenticateComplete = authenticateComplete;
exports.authenticateError = authenticateError;
var AUTHENTICATE_START = exports.AUTHENTICATE_START = "AUTHENTICATE_START";
var AUTHENTICATE_COMPLETE = exports.AUTHENTICATE_COMPLETE = "AUTHENTICATE_COMPLETE";
var AUTHENTICATE_ERROR = exports.AUTHENTICATE_ERROR = "AUTHENTICATE_ERROR";
function authenticateStart() {
return { type: AUTHENTICATE_START };
}
function authenticateComplete(user) {
return { type: AUTHENTICATE_COMPLETE, user: user };
}
function authenticateError(errors) {
return { type: AUTHENTICATE_ERROR, errors: errors };
}
/***/ },
/* 76 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hideEmailSignInSuccessModal = hideEmailSignInSuccessModal;
exports.hideEmailSignInErrorModal = hideEmailSignInErrorModal;
exports.hideOAuthSignInSuccessModal = hideOAuthSignInSuccessModal;
exports.hideOAuthSignInErrorModal = hideOAuthSignInErrorModal;
exports.hideSignOutSuccessModal = hideSignOutSuccessModal;
exports.hideSignOutErrorModal = hideSignOutErrorModal;
exports.hideEmailSignUpSuccessModal = hideEmailSignUpSuccessModal;
exports.hideEmailSignUpErrorModal = hideEmailSignUpErrorModal;
exports.showFirstTimeLoginSuccessModal = showFirstTimeLoginSuccessModal;
exports.showPasswordResetSuccessModal = showPasswordResetSuccessModal;
exports.hideFirstTimeLoginSuccessModal = hideFirstTimeLoginSuccessModal;
exports.hidePasswordResetSuccessModal = hidePasswordResetSuccessModal;
exports.showFirstTimeLoginErrorModal = showFirstTimeLoginErrorModal;
exports.showPasswordResetErrorModal = showPasswordResetErrorModal;
exports.hideFirstTimeLoginErrorModal = hideFirstTimeLoginErrorModal;
exports.hidePasswordResetErrorModal = hidePasswordResetErrorModal;
exports.hidePasswordResetRequestSuccessModal = hidePasswordResetRequestSuccessModal;
exports.hidePasswordResetRequestErrorModal = hidePasswordResetRequestErrorModal;
exports.hideUpdatePasswordSuccessModal = hideUpdatePasswordSuccessModal;
exports.hideUpdatePasswordErrorModal = hideUpdatePasswordErrorModal;
exports.hideDestroyAccountSuccessModal = hideDestroyAccountSuccessModal;
exports.hideDestroyAccountErrorModal = hideDestroyAccountErrorModal;
var HIDE_EMAIL_SIGN_IN_SUCCESS_MODAL = exports.HIDE_EMAIL_SIGN_IN_SUCCESS_MODAL = "HIDE_EMAIL_SIGN_IN_SUCCESS_MODAL";
var HIDE_EMAIL_SIGN_IN_ERROR_MODAL = exports.HIDE_EMAIL_SIGN_IN_ERROR_MODAL = "HIDE_EMAIL_SIGN_IN_ERROR_MODAL";
var HIDE_OAUTH_SIGN_IN_SUCCESS_MODAL = exports.HIDE_OAUTH_SIGN_IN_SUCCESS_MODAL = "HIDE_OAUTH_SIGN_IN_SUCCESS_MODAL";
var HIDE_OAUTH_SIGN_IN_ERROR_MODAL = exports.HIDE_OAUTH_SIGN_IN_ERROR_MODAL = "HIDE_OAUTH_SIGN_IN_ERROR_MODAL";
var HIDE_SIGN_OUT_ERROR_MODAL = exports.HIDE_SIGN_OUT_ERROR_MODAL = "HIDE_SIGN_OUT_ERROR_MODAL";
var HIDE_SIGN_OUT_SUCCESS_MODAL = exports.HIDE_SIGN_OUT_SUCCESS_MODAL = "HIDE_SIGN_OUT_SUCCESS_MODAL";
var HIDE_EMAIL_SIGN_UP_SUCCESS_MODAL = exports.HIDE_EMAIL_SIGN_UP_SUCCESS_MODAL = "HIDE_EMAIL_SIGN_UP_SUCCESS_MODAL";
var HIDE_EMAIL_SIGN_UP_ERROR_MODAL = exports.HIDE_EMAIL_SIGN_UP_ERROR_MODAL = "HIDE_EMAIL_SIGN_UP_ERROR_MODAL";
var SHOW_FIRST_TIME_LOGIN_SUCCESS_MODAL = exports.SHOW_FIRST_TIME_LOGIN_SUCCESS_MODAL = "SHOW_FIRST_TIME_LOGIN_SUCCESS_MODAL";
var HIDE_FIRST_TIME_LOGIN_SUCCESS_MODAL = exports.HIDE_FIRST_TIME_LOGIN_SUCCESS_MODAL = "HIDE_FIRST_TIME_LOGIN_SUCCESS_MODAL";
var HIDE_PASSWORD_RESET_SUCCESS_MODAL = exports.HIDE_PASSWORD_RESET_SUCCESS_MODAL = "HIDE_PASSWORD_RESET_SUCCESS_MODAL";
var SHOW_PASSWORD_RESET_SUCCESS_MODAL = exports.SHOW_PASSWORD_RESET_SUCCESS_MODAL = "SHOW_PASSWORD_RESET_SUCCESS_MODAL";
var SHOW_FIRST_TIME_LOGIN_ERROR_MODAL = exports.SHOW_FIRST_TIME_LOGIN_ERROR_MODAL = "SHOW_FIRST_TIME_LOGIN_ERROR_MODAL";
var HIDE_FIRST_TIME_LOGIN_ERROR_MODAL = exports.HIDE_FIRST_TIME_LOGIN_ERROR_MODAL = "HIDE_FIRST_TIME_LOGIN_ERROR_MODAL";
var HIDE_PASSWORD_RESET_ERROR_MODAL = exports.HIDE_PASSWORD_RESET_ERROR_MODAL = "HIDE_PASSWORD_RESET_ERROR_MODAL";
var SHOW_PASSWORD_RESET_ERROR_MODAL = exports.SHOW_PASSWORD_RESET_ERROR_MODAL = "SHOW_PASSWORD_RESET_ERROR_MODAL";
var HIDE_REQUEST_PASSWORD_RESET_SUCCESS_MODAL = exports.HIDE_REQUEST_PASSWORD_RESET_SUCCESS_MODAL = "HIDE_REQUEST_PASSWORD_RESET_SUCCESS_MODAL";
var HIDE_REQUEST_PASSWORD_RESET_ERROR_MODAL = exports.HIDE_REQUEST_PASSWORD_RESET_ERROR_MODAL = "HIDE_REQUEST_PASSWORD_RESET_ERROR_MODAL";
var HIDE_UPDATE_PASSWORD_SUCCESS_MODAL = exports.HIDE_UPDATE_PASSWORD_SUCCESS_MODAL = "HIDE_UPDATE_PASSWORD_SUCCESS_MODAL";
var HIDE_UPDATE_PASSWORD_ERROR_MODAL = exports.HIDE_UPDATE_PASSWORD_ERROR_MODAL = "HIDE_UPDATE_PASSWORD_ERROR_MODAL";
var HIDE_DESTROY_ACCOUNT_SUCCESS_MODAL = exports.HIDE_DESTROY_ACCOUNT_SUCCESS_MODAL = "HIDE_DESTROY_ACCOUNT_SUCCESS_MODAL";
var HIDE_DESTROY_ACCOUNT_ERROR_MODAL = exports.HIDE_DESTROY_ACCOUNT_ERROR_MODAL = "HIDE_DESTROY_ACCOUNT_ERROR_MODAL";
function hideEmailSignInSuccessModal() {
return { type: HIDE_EMAIL_SIGN_IN_SUCCESS_MODAL };
}
function hideEmailSignInErrorModal() {
return { type: HIDE_EMAIL_SIGN_IN_ERROR_MODAL };
}
function hideOAuthSignInSuccessModal() {
return { type: HIDE_OAUTH_SIGN_IN_SUCCESS_MODAL };
}
function hideOAuthSignInErrorModal() {
return { type: HIDE_OAUTH_SIGN_IN_ERROR_MODAL };
}
function hideSignOutSuccessModal() {
return { type: HIDE_SIGN_OUT_SUCCESS_MODAL };
}
function hideSignOutErrorModal() {
return { type: HIDE_SIGN_OUT_ERROR_MODAL };
}
function hideEmailSignUpSuccessModal() {
return { type: HIDE_EMAIL_SIGN_UP_SUCCESS_MODAL };
}
function hideEmailSignUpErrorModal() {
return { type: HIDE_EMAIL_SIGN_UP_ERROR_MODAL };
}
function showFirstTimeLoginSuccessModal() {
return { type: SHOW_FIRST_TIME_LOGIN_SUCCESS_MODAL };
}
function showPasswordResetSuccessModal() {
return { type: SHOW_PASSWORD_RESET_SUCCESS_MODAL };
}
function hideFirstTimeLoginSuccessModal() {
return { type: HIDE_FIRST_TIME_LOGIN_SUCCESS_MODAL };
}
function hidePasswordResetSuccessModal() {
return { type: HIDE_PASSWORD_RESET_SUCCESS_MODAL };
}
function showFirstTimeLoginErrorModal() {
return { type: SHOW_FIRST_TIME_LOGIN_ERROR_MODAL };
}
function showPasswordResetErrorModal() {
return { type: SHOW_PASSWORD_RESET_ERROR_MODAL };
}
function hideFirstTimeLoginErrorModal() {
return { type: HIDE_FIRST_TIME_LOGIN_ERROR_MODAL };
}
function hidePasswordResetErrorModal() {
return { type: HIDE_PASSWORD_RESET_ERROR_MODAL };
}
function hidePasswordResetRequestSuccessModal() {
return { type: HIDE_REQUEST_PASSWORD_RESET_SUCCESS_MODAL };
}
function hidePasswordResetRequestErrorModal() {
return { type: HIDE_REQUEST_PASSWORD_RESET_ERROR_MODAL };
}
function hideUpdatePasswordSuccessModal() {
return { type: HIDE_UPDATE_PASSWORD_SUCCESS_MODAL };
}
function hideUpdatePasswordErrorModal() {
return { type: HIDE_UPDATE_PASSWORD_ERROR_MODAL };
}
function hideDestroyAccountSuccessModal() {
return { type: HIDE_DESTROY_ACCOUNT_SUCCESS_MODAL };
}
function hideDestroyAccountErrorModal() {
return { type: HIDE_DESTROY_ACCOUNT_ERROR_MODAL };
}
/***/ },
/* 77 */
/***/ function(module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ssAuthTokenUpdate = ssAuthTokenUpdate;
var SS_AUTH_TOKEN_UPDATE = exports.SS_AUTH_TOKEN_UPDATE = "SS_AUTH_TOKEN_UPDATE";
function ssAuthTokenUpdate(_ref) {
var user = _ref.user,
headers = _ref.headers,
mustResetPassword = _ref.mustResetPassword,
firstTimeLogin = _ref.firstTimeLogin,
endpointKey = _ref.endpointKey;
return { type: SS_AUTH_TOKEN_UPDATE, user: user, headers: headers, mustResetPassword: mustResetPassword, firstTimeLogin: firstTimeLogin, endpointKey: endpointKey };
}
/***/ },
/* 78 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.applyConfig = applyConfig;
var _constants = __webpack_require__(74);
var C = _interopRequireWildcard(_constants);
var _extend = __webpack_require__(64);
var _extend2 = _interopRequireDefault(_extend);
var _fetch = __webpack_require__(79);
var _fetch2 = _interopRequireDefault(_fetch);
var _parseEndpointConfig2 = __webpack_require__(83);
var _parseEndpointConfig3 = _interopRequireDefault(_parseEndpointConfig2);
var _handleFetchResponse = __webpack_require__(84);
var _configure = __webpack_require__(73);
var _sessionStorage = __webpack_require__(81);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
// can't use "window" with node app
var root = Function("return this")() || (42, eval)("this");
var defaultSettings = {
proxyIf: function proxyIf() {
return false;
},
proxyUrl: "/proxy",
forceHardRedirect: false,
storage: "cookies",
cookieExpiry: 14,
cookiePath: "/",
initialCredentials: null,
passwordResetSuccessUrl: function passwordResetSuccessUrl() {
return root.location.href;
},
confirmationSuccessUrl: function confirmationSuccessUrl() {
return root.location.href;
},
tokenFormat: {
"access-token": "{{ access-token }}",
"token-type": "Bearer",
client: "{{ client }}",
expiry: "{{ expiry }}",
uid: "{{ uid }}"
},
parseExpiry: function parseExpiry(headers) {
// convert from ruby time (seconds) to js time (millis)
return parseInt(headers["expiry"], 10) * 1000 || null;
},
handleLoginResponse: function handleLoginResponse(resp) {
return resp.data;
},
handleAccountUpdateResponse: function handleAccountUpdateResponse(resp) {
return resp.data;
},
handleTokenValidationResponse: function handleTokenValidationResponse(resp) {
return resp.data;
}
};
// save session configuration
function applyConfig() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
dispatch = _ref.dispatch,
_ref$endpoint = _ref.endpoint,
endpoint = _ref$endpoint === undefined ? {} : _ref$endpoint,
_ref$settings = _ref.settings,
settings = _ref$settings === undefined ? {} : _ref$settings,
_ref$reset = _ref.reset,
reset = _ref$reset === undefined ? false : _ref$reset;
var currentEndpointKey = void 0;
if (reset) {
resetConfig();
}
if (settings.initialCredentials) {
currentEndpointKey = settings.initialCredentials.currentEndpointKey;
}
(0, _sessionStorage.setCurrentSettings)((0, _extend2.default)({}, defaultSettings, settings));
var _parseEndpointConfig = (0, _parseEndpointConfig3.default)(endpoint, (0, _sessionStorage.getInitialEndpointKey)()),
defaultEndpointKey = _parseEndpointConfig.defaultEndpointKey,
currentEndpoint = _parseEndpointConfig.currentEndpoint;
if (!currentEndpointKey) {
currentEndpointKey = defaultEndpointKey;
}
// persist default config key with session storage
(0, _sessionStorage.setDefaultEndpointKey)(defaultEndpointKey);
(0, _sessionStorage.setCurrentEndpoint)(currentEndpoint);
dispatch((0, _configure.setEndpointKeys)(Object.keys(currentEndpoint), currentEndpointKey, defaultEndpointKey));
(0, _sessionStorage.setCurrentEndpointKey)(currentEndpointKey);
var savedCreds = (0, _sessionStorage.retrieveData)(C.SAVED_CREDS_KEY);
if ((0, _sessionStorage.getCurrentSettings)().initialCredentials) {
// skip initial headers check (i.e. check was already done server-side)
var headers = (0, _sessionStorage.getCurrentSettings)().initialCredentials.headers;