@rownd/react-native 0.2.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +34 -52
  3. package/android/build.gradle +127 -37
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +1 -1
  6. package/android/src/main/java/com/reactnativerowndplugin/RowndPluginModule.kt +98 -0
  7. package/android/src/main/java/com/reactnativerowndplugin/RowndPluginPackage.kt +16 -0
  8. package/ios/{ReactNative.xcodeproj → Rownd.xcodeproj}/project.pbxproj +13 -12
  9. package/ios/RowndPlugin-Bridging-Header.h +3 -0
  10. package/ios/RowndPlugin.m +26 -0
  11. package/ios/RowndPlugin.swift +83 -0
  12. package/ios/RowndPluginEventEmitter.m +12 -0
  13. package/ios/RowndPluginEventEmitter.swift +19 -0
  14. package/lib/commonjs/components/GlobalContext.js +32 -298
  15. package/lib/commonjs/components/GlobalContext.js.map +1 -1
  16. package/lib/commonjs/components/{BottomSheetTextInput/types.js → GlobalContext.types.js} +1 -1
  17. package/lib/commonjs/components/GlobalContext.types.js.map +1 -0
  18. package/lib/commonjs/constants/action.js +13 -0
  19. package/lib/commonjs/constants/action.js.map +1 -0
  20. package/lib/commonjs/hooks/rownd.js +15 -146
  21. package/lib/commonjs/hooks/rownd.js.map +1 -1
  22. package/lib/commonjs/index.js +2 -12
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/reducer/rowndReducer.js +89 -0
  25. package/lib/commonjs/reducer/rowndReducer.js.map +1 -0
  26. package/lib/commonjs/utils/config.js +0 -26
  27. package/lib/commonjs/utils/config.js.map +1 -1
  28. package/lib/commonjs/utils/nativeModule.js +72 -0
  29. package/lib/commonjs/utils/nativeModule.js.map +1 -0
  30. package/lib/module/components/GlobalContext.js +30 -293
  31. package/lib/module/components/GlobalContext.js.map +1 -1
  32. package/lib/module/components/GlobalContext.types.js +2 -0
  33. package/lib/module/components/GlobalContext.types.js.map +1 -0
  34. package/lib/module/constants/action.js +6 -0
  35. package/lib/module/constants/action.js.map +1 -0
  36. package/lib/module/hooks/rownd.js +12 -137
  37. package/lib/module/hooks/rownd.js.map +1 -1
  38. package/lib/module/index.js +2 -4
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/reducer/rowndReducer.js +78 -0
  41. package/lib/module/reducer/rowndReducer.js.map +1 -0
  42. package/lib/module/utils/config.js +1 -16
  43. package/lib/module/utils/config.js.map +1 -1
  44. package/lib/module/utils/nativeModule.js +48 -0
  45. package/lib/module/utils/nativeModule.js.map +1 -0
  46. package/lib/typescript/components/GlobalContext.d.ts +13 -0
  47. package/lib/typescript/{src/components/GlobalContext.d.ts → components/GlobalContext.types.d.ts} +9 -35
  48. package/lib/typescript/constants/action.d.ts +7 -0
  49. package/lib/typescript/{src/hooks → hooks}/rownd.d.ts +10 -13
  50. package/lib/typescript/index.d.ts +3 -0
  51. package/lib/typescript/reducer/rowndReducer.d.ts +4 -0
  52. package/lib/typescript/utils/config.d.ts +10 -0
  53. package/lib/typescript/utils/nativeModule.d.ts +10 -0
  54. package/package.json +36 -56
  55. package/rownd-react-native.podspec +36 -0
  56. package/src/components/GlobalContext.tsx +47 -457
  57. package/src/components/GlobalContext.types.ts +105 -0
  58. package/src/constants/action.ts +8 -0
  59. package/src/hooks/rownd.ts +29 -147
  60. package/src/index.tsx +2 -4
  61. package/src/reducer/rowndReducer.ts +78 -0
  62. package/src/utils/config.ts +0 -27
  63. package/src/utils/nativeModule.ts +69 -0
  64. package/android/src/main/java/com/reactnative/ReactNativePackage.java +0 -22
  65. package/android/src/main/java/com/reactnative/ReactNativeViewManager.java +0 -31
  66. package/ios/ReactNativeViewManager.m +0 -34
  67. package/lib/commonjs/assets/images/checkmark--filled.svg +0 -12
  68. package/lib/commonjs/assets/images/email-verify-waiting.svg +0 -36
  69. package/lib/commonjs/assets/images/error-icon-material.svg +0 -1
  70. package/lib/commonjs/assets/images/phone-verify-waiting.svg +0 -26
  71. package/lib/commonjs/components/AuthenticatedComponent.js +0 -35
  72. package/lib/commonjs/components/AuthenticatedComponent.js.map +0 -1
  73. package/lib/commonjs/components/AutoSigninDialog.js +0 -132
  74. package/lib/commonjs/components/AutoSigninDialog.js.map +0 -1
  75. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -65
  76. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  77. package/lib/commonjs/components/BottomSheetTextInput/index.js +0 -24
  78. package/lib/commonjs/components/BottomSheetTextInput/index.js.map +0 -1
  79. package/lib/commonjs/components/BottomSheetTextInput/types.js.map +0 -1
  80. package/lib/commonjs/components/DarkText.js +0 -35
  81. package/lib/commonjs/components/DarkText.js.map +0 -1
  82. package/lib/commonjs/components/DefaultContext.js +0 -266
  83. package/lib/commonjs/components/DefaultContext.js.map +0 -1
  84. package/lib/commonjs/components/RowndComponents.js +0 -25
  85. package/lib/commonjs/components/RowndComponents.js.map +0 -1
  86. package/lib/commonjs/components/RowndProvider.js +0 -55
  87. package/lib/commonjs/components/RowndProvider.js.map +0 -1
  88. package/lib/commonjs/components/SignIn.js +0 -644
  89. package/lib/commonjs/components/SignIn.js.map +0 -1
  90. package/lib/commonjs/components/images/CheckmarkFilled.js +0 -40
  91. package/lib/commonjs/components/images/CheckmarkFilled.js.map +0 -1
  92. package/lib/commonjs/components/images/EmailVerifyWaiting.js +0 -100
  93. package/lib/commonjs/components/images/EmailVerifyWaiting.js.map +0 -1
  94. package/lib/commonjs/components/images/ErrorIcon.js +0 -31
  95. package/lib/commonjs/components/images/ErrorIcon.js.map +0 -1
  96. package/lib/commonjs/components/images/PhoneVerifyWaiting.js +0 -91
  97. package/lib/commonjs/components/images/PhoneVerifyWaiting.js.map +0 -1
  98. package/lib/commonjs/data/actions.js +0 -26
  99. package/lib/commonjs/data/actions.js.map +0 -1
  100. package/lib/commonjs/hooks/api.js +0 -155
  101. package/lib/commonjs/hooks/api.js.map +0 -1
  102. package/lib/commonjs/hooks/debounce.js +0 -38
  103. package/lib/commonjs/hooks/debounce.js.map +0 -1
  104. package/lib/commonjs/hooks/fingerprint.js +0 -176
  105. package/lib/commonjs/hooks/fingerprint.js.map +0 -1
  106. package/lib/commonjs/hooks/index.js +0 -48
  107. package/lib/commonjs/hooks/index.js.map +0 -1
  108. package/lib/commonjs/hooks/interval.js +0 -31
  109. package/lib/commonjs/hooks/interval.js.map +0 -1
  110. package/lib/commonjs/hooks/nav.js +0 -39
  111. package/lib/commonjs/hooks/nav.js.map +0 -1
  112. package/lib/commonjs/index.tsx.bak +0 -26
  113. package/lib/commonjs/types.js +0 -2
  114. package/lib/commonjs/types.js.map +0 -1
  115. package/lib/commonjs/utils/events.js +0 -57
  116. package/lib/commonjs/utils/events.js.map +0 -1
  117. package/lib/commonjs/utils/form.js +0 -46
  118. package/lib/commonjs/utils/form.js.map +0 -1
  119. package/lib/commonjs/utils/queue.js +0 -117
  120. package/lib/commonjs/utils/queue.js.map +0 -1
  121. package/lib/commonjs/utils/storage.js +0 -15
  122. package/lib/commonjs/utils/storage.js.map +0 -1
  123. package/lib/commonjs/utils/tokens.js +0 -35
  124. package/lib/commonjs/utils/tokens.js.map +0 -1
  125. package/lib/commonjs/utils/user-data.js +0 -21
  126. package/lib/commonjs/utils/user-data.js.map +0 -1
  127. package/lib/module/assets/images/checkmark--filled.svg +0 -12
  128. package/lib/module/assets/images/email-verify-waiting.svg +0 -36
  129. package/lib/module/assets/images/error-icon-material.svg +0 -1
  130. package/lib/module/assets/images/phone-verify-waiting.svg +0 -26
  131. package/lib/module/components/AuthenticatedComponent.js +0 -24
  132. package/lib/module/components/AuthenticatedComponent.js.map +0 -1
  133. package/lib/module/components/AutoSigninDialog.js +0 -110
  134. package/lib/module/components/AutoSigninDialog.js.map +0 -1
  135. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -52
  136. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  137. package/lib/module/components/BottomSheetTextInput/index.js +0 -5
  138. package/lib/module/components/BottomSheetTextInput/index.js.map +0 -1
  139. package/lib/module/components/BottomSheetTextInput/types.js +0 -2
  140. package/lib/module/components/BottomSheetTextInput/types.js.map +0 -1
  141. package/lib/module/components/DarkText.js +0 -24
  142. package/lib/module/components/DarkText.js.map +0 -1
  143. package/lib/module/components/DefaultContext.js +0 -244
  144. package/lib/module/components/DefaultContext.js.map +0 -1
  145. package/lib/module/components/RowndComponents.js +0 -12
  146. package/lib/module/components/RowndComponents.js.map +0 -1
  147. package/lib/module/components/RowndProvider.js +0 -39
  148. package/lib/module/components/RowndProvider.js.map +0 -1
  149. package/lib/module/components/SignIn.js +0 -616
  150. package/lib/module/components/SignIn.js.map +0 -1
  151. package/lib/module/components/images/CheckmarkFilled.js +0 -27
  152. package/lib/module/components/images/CheckmarkFilled.js.map +0 -1
  153. package/lib/module/components/images/EmailVerifyWaiting.js +0 -87
  154. package/lib/module/components/images/EmailVerifyWaiting.js.map +0 -1
  155. package/lib/module/components/images/ErrorIcon.js +0 -18
  156. package/lib/module/components/images/ErrorIcon.js.map +0 -1
  157. package/lib/module/components/images/PhoneVerifyWaiting.js +0 -78
  158. package/lib/module/components/images/PhoneVerifyWaiting.js.map +0 -1
  159. package/lib/module/data/actions.js +0 -19
  160. package/lib/module/data/actions.js.map +0 -1
  161. package/lib/module/hooks/api.js +0 -135
  162. package/lib/module/hooks/api.js.map +0 -1
  163. package/lib/module/hooks/debounce.js +0 -29
  164. package/lib/module/hooks/debounce.js.map +0 -1
  165. package/lib/module/hooks/fingerprint.js +0 -157
  166. package/lib/module/hooks/fingerprint.js.map +0 -1
  167. package/lib/module/hooks/index.js +0 -7
  168. package/lib/module/hooks/index.js.map +0 -1
  169. package/lib/module/hooks/interval.js +0 -23
  170. package/lib/module/hooks/interval.js.map +0 -1
  171. package/lib/module/hooks/nav.js +0 -30
  172. package/lib/module/hooks/nav.js.map +0 -1
  173. package/lib/module/index.tsx.bak +0 -26
  174. package/lib/module/types.js +0 -2
  175. package/lib/module/types.js.map +0 -1
  176. package/lib/module/utils/events.js +0 -45
  177. package/lib/module/utils/events.js.map +0 -1
  178. package/lib/module/utils/form.js +0 -34
  179. package/lib/module/utils/form.js.map +0 -1
  180. package/lib/module/utils/queue.js +0 -109
  181. package/lib/module/utils/queue.js.map +0 -1
  182. package/lib/module/utils/storage.js +0 -6
  183. package/lib/module/utils/storage.js.map +0 -1
  184. package/lib/module/utils/tokens.js +0 -24
  185. package/lib/module/utils/tokens.js.map +0 -1
  186. package/lib/module/utils/user-data.js +0 -14
  187. package/lib/module/utils/user-data.js.map +0 -1
  188. package/lib/package.json +0 -173
  189. package/lib/typescript/src/components/AuthenticatedComponent.d.ts +0 -7
  190. package/lib/typescript/src/components/AutoSigninDialog.d.ts +0 -2
  191. package/lib/typescript/src/components/BottomSheetTextInput/BottomSheetTextInput.d.ts +0 -4
  192. package/lib/typescript/src/components/BottomSheetTextInput/index.d.ts +0 -2
  193. package/lib/typescript/src/components/BottomSheetTextInput/types.d.ts +0 -3
  194. package/lib/typescript/src/components/DarkText.d.ts +0 -3
  195. package/lib/typescript/src/components/DefaultContext.d.ts +0 -12
  196. package/lib/typescript/src/components/RowndComponents.d.ts +0 -2
  197. package/lib/typescript/src/components/RowndProvider.d.ts +0 -8
  198. package/lib/typescript/src/components/SignIn.d.ts +0 -2
  199. package/lib/typescript/src/components/images/CheckmarkFilled.d.ts +0 -4
  200. package/lib/typescript/src/components/images/EmailVerifyWaiting.d.ts +0 -4
  201. package/lib/typescript/src/components/images/ErrorIcon.d.ts +0 -4
  202. package/lib/typescript/src/components/images/PhoneVerifyWaiting.d.ts +0 -4
  203. package/lib/typescript/src/data/actions.d.ts +0 -20
  204. package/lib/typescript/src/hooks/api.d.ts +0 -12
  205. package/lib/typescript/src/hooks/debounce.d.ts +0 -5
  206. package/lib/typescript/src/hooks/fingerprint.d.ts +0 -12
  207. package/lib/typescript/src/hooks/index.d.ts +0 -6
  208. package/lib/typescript/src/hooks/interval.d.ts +0 -2
  209. package/lib/typescript/src/hooks/nav.d.ts +0 -6
  210. package/lib/typescript/src/index.d.ts +0 -4
  211. package/lib/typescript/src/types.d.ts +0 -26
  212. package/lib/typescript/src/utils/config.d.ts +0 -18
  213. package/lib/typescript/src/utils/events.d.ts +0 -22
  214. package/lib/typescript/src/utils/form.d.ts +0 -18
  215. package/lib/typescript/src/utils/queue.d.ts +0 -21
  216. package/lib/typescript/src/utils/storage.d.ts +0 -3
  217. package/lib/typescript/src/utils/tokens.d.ts +0 -4
  218. package/lib/typescript/src/utils/user-data.d.ts +0 -3
  219. package/react-native.podspec +0 -19
  220. package/src/assets/images/checkmark--filled.svg +0 -12
  221. package/src/assets/images/email-verify-waiting.svg +0 -36
  222. package/src/assets/images/error-icon-material.svg +0 -1
  223. package/src/assets/images/phone-verify-waiting.svg +0 -26
  224. package/src/components/AuthenticatedComponent.tsx +0 -30
  225. package/src/components/AutoSigninDialog.tsx +0 -131
  226. package/src/components/BottomSheetTextInput/BottomSheetTextInput.tsx +0 -57
  227. package/src/components/BottomSheetTextInput/index.ts +0 -5
  228. package/src/components/BottomSheetTextInput/types.ts +0 -3
  229. package/src/components/DarkText.tsx +0 -16
  230. package/src/components/DefaultContext.tsx +0 -278
  231. package/src/components/RowndComponents.tsx +0 -18
  232. package/src/components/RowndProvider.tsx +0 -56
  233. package/src/components/SignIn.tsx +0 -797
  234. package/src/components/images/CheckmarkFilled.tsx +0 -30
  235. package/src/components/images/EmailVerifyWaiting.tsx +0 -95
  236. package/src/components/images/ErrorIcon.tsx +0 -11
  237. package/src/components/images/PhoneVerifyWaiting.tsx +0 -74
  238. package/src/data/actions.ts +0 -21
  239. package/src/hooks/api.ts +0 -162
  240. package/src/hooks/debounce.ts +0 -36
  241. package/src/hooks/fingerprint.ts +0 -217
  242. package/src/hooks/index.ts +0 -7
  243. package/src/hooks/interval.ts +0 -25
  244. package/src/hooks/nav.tsx +0 -29
  245. package/src/index.tsx.bak +0 -26
  246. package/src/types.ts +0 -27
  247. package/src/utils/events.ts +0 -54
  248. package/src/utils/form.tsx +0 -64
  249. package/src/utils/queue.ts +0 -75
  250. package/src/utils/storage.ts +0 -7
  251. package/src/utils/tokens.ts +0 -26
  252. package/src/utils/user-data.ts +0 -15
@@ -1,616 +0,0 @@
1
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
4
- import { differenceInMinutes } from 'date-fns';
5
- import { View, StyleSheet, TouchableOpacity, Image, ActivityIndicator, Linking, Text } from 'react-native'; // import Text from './DarkText';
6
-
7
- import { SvgCssUri } from 'react-native-svg';
8
- import phone from 'phone';
9
- import jwt_decode from 'jwt-decode';
10
- import { BottomSheetBackdrop, BottomSheetModal } from '@gorhom/bottom-sheet';
11
- import BottomSheetTextInput from './BottomSheetTextInput';
12
- import bottomSheetMeta from '@gorhom/bottom-sheet/package.json';
13
- import { useApi, useInterval, useNav, useDeviceFingerprint } from '../hooks';
14
- import { useGlobalContext } from './GlobalContext';
15
- import { ActionType } from '../data/actions';
16
- import { renderField } from '../utils/form'; // Image imports
17
-
18
- import ImageEmailVerifyWaiting from './images/EmailVerifyWaiting';
19
- import ImagePhoneVerifyWaiting from './images/PhoneVerifyWaiting';
20
- import ImageCheckmarkFilled from './images/CheckmarkFilled';
21
- var LoginStep;
22
-
23
- (function (LoginStep) {
24
- LoginStep["INIT"] = "init";
25
- LoginStep["WAITING"] = "waiting";
26
- LoginStep["SUCCESS"] = "success";
27
- LoginStep["FAILURE"] = "failure";
28
- LoginStep["ERROR"] = "error";
29
- })(LoginStep || (LoginStep = {}));
30
-
31
- var LoginVerificationStatus;
32
-
33
- (function (LoginVerificationStatus) {
34
- LoginVerificationStatus["PENDING"] = "pending";
35
- LoginVerificationStatus["EXPIRED"] = "expired";
36
- LoginVerificationStatus["VERIFIED"] = "verified";
37
- })(LoginVerificationStatus || (LoginVerificationStatus = {}));
38
-
39
- export function SignIn() {
40
- var _decodedAccessToken, _nav$options, _app$config2, _app$config2$hub, _app$config2$hub$auth, _nav$options4, _nav$options5, _nav$options8, _state$config3, _nav$options10, _state$config5, _app$config5, _app$config6, _app$config6$hub, _app$config6$hub$auth, _app$config7, _app$config7$hub, _app$config7$hub$auth;
41
-
42
- const navTo = useNav();
43
- const {
44
- getFingerprint,
45
- getChallengeIfPresent,
46
- clearFingerprint
47
- } = useDeviceFingerprint();
48
- const {
49
- state,
50
- dispatch
51
- } = useGlobalContext();
52
- const {
53
- config,
54
- nav,
55
- app,
56
- user
57
- } = state;
58
- let decodedAccessToken;
59
-
60
- if (state.auth.access_token) {
61
- decodedAccessToken = jwt_decode(state.auth.access_token);
62
- }
63
-
64
- const [userIdentifier, setUserIdentifier] = useState('');
65
- const [fieldError, setFieldError] = useState(null);
66
- const [step, setStep] = useState(state.auth.access_token && ((_decodedAccessToken = decodedAccessToken) === null || _decodedAccessToken === void 0 ? void 0 : _decodedAccessToken['https://auth.rownd.io/is_verified_user']) !== false ? LoginStep.SUCCESS : LoginStep.INIT);
67
- const [error, setError] = useState('');
68
- const allowedIdentifiers = useMemo(() => ['email', 'phone'], []);
69
- const [requestId, setRequestId] = useState(null);
70
- const [loginPollStart, setLoginPollStart] = useState(null);
71
- const [isSubmitting, setIsSubmitting] = useState(false);
72
- const [loginType, setLoginType] = useState(null); // eslint-disable-next-line @typescript-eslint/no-unused-vars
73
-
74
- const [_phoneDetails, setPhoneDetails] = useState(null); // TODO: For parity with web, need to use `phoneDetails` to update the input visuals
75
-
76
- const [isValidUserIdentifier, setIsValidUserIdentifier] = useState(false);
77
- const [requiresAdditionalFields, setRequiresAdditionalFields] = useState(nav === null || nav === void 0 ? void 0 : (_nav$options = nav.options) === null || _nav$options === void 0 ? void 0 : _nav$options.init_data);
78
- const bottomSheetModalRef = useRef(null);
79
- useEffect(() => {
80
- if (bottomSheetModalRef.current) {
81
- bottomSheetModalRef.current.present();
82
- }
83
- }, []);
84
- const addlFieldInit = useCallback(currentState => {
85
- var _app$config, _app$config$hub, _app$config$hub$auth, _nav$options2, _nav$options3;
86
-
87
- const addlFields = app === null || app === void 0 ? void 0 : (_app$config = app.config) === null || _app$config === void 0 ? void 0 : (_app$config$hub = _app$config.hub) === null || _app$config$hub === void 0 ? void 0 : (_app$config$hub$auth = _app$config$hub.auth) === null || _app$config$hub$auth === void 0 ? void 0 : _app$config$hub$auth.additional_fields;
88
- const addlInputs = (nav === null || nav === void 0 ? void 0 : (_nav$options2 = nav.options) === null || _nav$options2 === void 0 ? void 0 : _nav$options2.init_data) || (nav === null || nav === void 0 ? void 0 : (_nav$options3 = nav.options) === null || _nav$options3 === void 0 ? void 0 : _nav$options3.default_values) || {};
89
- const newState = {};
90
-
91
- if (addlFields !== null && addlFields !== void 0 && addlFields.length) {
92
- for (const field of addlFields) {
93
- if (field !== null && field !== void 0 && field.options) {
94
- newState[field.name] = (addlInputs === null || addlInputs === void 0 ? void 0 : addlInputs[field.name]) || field.options[0].value;
95
- }
96
- }
97
- }
98
-
99
- return { ...currentState,
100
- ...newState
101
- };
102
- }, [app === null || app === void 0 ? void 0 : (_app$config2 = app.config) === null || _app$config2 === void 0 ? void 0 : (_app$config2$hub = _app$config2.hub) === null || _app$config2$hub === void 0 ? void 0 : (_app$config2$hub$auth = _app$config2$hub.auth) === null || _app$config2$hub$auth === void 0 ? void 0 : _app$config2$hub$auth.additional_fields, nav === null || nav === void 0 ? void 0 : (_nav$options4 = nav.options) === null || _nav$options4 === void 0 ? void 0 : _nav$options4.default_values, nav === null || nav === void 0 ? void 0 : (_nav$options5 = nav.options) === null || _nav$options5 === void 0 ? void 0 : _nav$options5.init_data]);
103
- const fieldReducer = useCallback((currentState, action) => {
104
- console.log('fieldReducer', action);
105
-
106
- switch (action.type) {
107
- case 'reset':
108
- return addlFieldInit(currentState);
109
-
110
- default:
111
- return { ...currentState,
112
- ...action.payload
113
- };
114
- }
115
- }, [addlFieldInit]);
116
- const [addlFieldValues, addlFieldDispatch] = useReducer(fieldReducer, {}, addlFieldInit);
117
- const {
118
- client: api
119
- } = useApi();
120
-
121
- function validateEmail(email) {
122
- const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
123
- const isValid = re.test(String(email).toLowerCase());
124
-
125
- if (!isValid) {
126
- setFieldError('Invalid email address');
127
- return false;
128
- }
129
-
130
- setFieldError(null);
131
- return true;
132
- }
133
-
134
- const isValidPhone = useCallback(() => {
135
- const phoneResult = phone(userIdentifier);
136
-
137
- if (!phoneResult.isValid) {
138
- setLoginType(null);
139
- setPhoneDetails(null);
140
- return false;
141
- }
142
-
143
- setLoginType('phone');
144
- setPhoneDetails(phoneResult);
145
- setUserIdentifier(phoneResult.phoneNumber);
146
- return true;
147
- }, [userIdentifier]);
148
- const isValidEmail = useCallback(() => {
149
- const emailAtIdx = userIdentifier === null || userIdentifier === void 0 ? void 0 : userIdentifier.indexOf('@');
150
- const emailSuffixIdx = userIdentifier === null || userIdentifier === void 0 ? void 0 : userIdentifier.substring(emailAtIdx).indexOf('.');
151
-
152
- if (emailAtIdx > 0 && emailSuffixIdx > 0 && (userIdentifier === null || userIdentifier === void 0 ? void 0 : userIdentifier.substring(emailAtIdx + emailSuffixIdx).length) >= 3) {
153
- return validateEmail(userIdentifier);
154
- }
155
-
156
- return false;
157
- }, [userIdentifier]);
158
- const validateInput = useCallback(() => {
159
- const validations = [];
160
-
161
- if (allowedIdentifiers.includes('phone')) {
162
- validations.push(isValidPhone);
163
- }
164
-
165
- if (allowedIdentifiers.includes('email')) {
166
- validations.push(isValidEmail);
167
- }
168
-
169
- if (!validations.some(fn => fn())) {
170
- setIsValidUserIdentifier(false);
171
- } else {
172
- setIsValidUserIdentifier(true);
173
- }
174
- }, [allowedIdentifiers, isValidEmail, isValidPhone]); // Fire validation as data changes in field
175
-
176
- useEffect(validateInput, [validateInput]);
177
- const pollLoginStatus = useCallback(async () => {
178
- try {
179
- const resp = await api.post(`hub/auth/challenge_status`, {
180
- headers: {
181
- 'x-rownd-app-key': config === null || config === void 0 ? void 0 : config.appKey
182
- },
183
- json: {
184
- challenge_id: requestId,
185
- [loginType === 'phone' ? 'phone' : 'email']: userIdentifier
186
- }
187
- }).json();
188
- let err;
189
-
190
- switch (resp.status) {
191
- case 'pending':
192
- err = new Error('Login challenge is still pending');
193
- err.code = LoginVerificationStatus.PENDING;
194
- throw err;
195
-
196
- case 'expired':
197
- err = new Error('Login challenge is still pending');
198
- err.code = LoginVerificationStatus.PENDING;
199
- throw err;
200
-
201
- case 'verified':
202
- break;
203
-
204
- default:
205
- err = new Error('Unknown login challenge status');
206
- throw err;
207
- }
208
-
209
- dispatch({
210
- type: ActionType.LOGIN_SUCCESS,
211
- payload: resp
212
- });
213
- setStep(LoginStep.SUCCESS);
214
- } catch (err) {
215
- // logger.log('login poll error', err);
216
- // If network error, try again up to 1 minute, else fail
217
- if (!err.code && differenceInMinutes(Date.now(), loginPollStart) > 0) {
218
- setStep(LoginStep.ERROR);
219
- setError('Network error. Please try again later.');
220
- return;
221
- } // If request expires, then fail (assume > 6 mins is a failure/expiration)
222
-
223
-
224
- if ((err.status || err.code) && differenceInMinutes(Date.now(), loginPollStart) > 6) {
225
- setStep(LoginStep.ERROR);
226
- setError('The sign in request expired.');
227
- return;
228
- }
229
-
230
- if (err.status && err.status >= 400) {
231
- setStep(LoginStep.FAILURE);
232
- setError('Sign in unsuccessful.');
233
- }
234
- }
235
- }, [api, config === null || config === void 0 ? void 0 : config.appKey, dispatch, loginPollStart, loginType, requestId, userIdentifier]); // Polling when a login flow is in progress
236
-
237
- useInterval(pollLoginStatus, step === LoginStep.WAITING ? 5000 : null); // login polling manager
238
-
239
- useEffect(() => {
240
- if (step === LoginStep.SUCCESS) {
241
- var _nav$options6, _state$config;
242
-
243
- if (nav !== null && nav !== void 0 && (_nav$options6 = nav.options) !== null && _nav$options6 !== void 0 && _nav$options6.post_login_redirect || (_state$config = state.config) !== null && _state$config !== void 0 && _state$config.postLoginUrl) {
244
- var _nav$options7, _state$config2;
245
-
246
- Linking.openURL((nav === null || nav === void 0 ? void 0 : (_nav$options7 = nav.options) === null || _nav$options7 === void 0 ? void 0 : _nav$options7.post_login_redirect) || ((_state$config2 = state.config) === null || _state$config2 === void 0 ? void 0 : _state$config2.postLoginUrl));
247
- }
248
-
249
- dispatch({
250
- type: ActionType.CHANGE_ROUTE,
251
- payload: {
252
- route: '/'
253
- }
254
- }); // Reset modal state if this user is unverified, since we'll need to re-submit at some point
255
-
256
- if (!state.auth.is_verified_user) {
257
- setStep(LoginStep.INIT);
258
- }
259
- }
260
- }, [dispatch, nav === null || nav === void 0 ? void 0 : (_nav$options8 = nav.options) === null || _nav$options8 === void 0 ? void 0 : _nav$options8.post_login_redirect, pollLoginStatus, state.auth.is_verified_user, (_state$config3 = state.config) === null || _state$config3 === void 0 ? void 0 : _state$config3.postLoginUrl, step]);
261
- const initSignIn = useCallback(async () => {
262
- var _nav$options9, _state$config4, _app$config3;
263
-
264
- if (step === LoginStep.WAITING) {
265
- return;
266
- } // Validation
267
-
268
-
269
- if (fieldError) {
270
- return;
271
- }
272
-
273
- const payload = {
274
- [loginType === 'phone' ? 'phone' : 'email']: userIdentifier,
275
- return_url: (nav === null || nav === void 0 ? void 0 : (_nav$options9 = nav.options) === null || _nav$options9 === void 0 ? void 0 : _nav$options9.post_login_redirect) || ((_state$config4 = state.config) === null || _state$config4 === void 0 ? void 0 : _state$config4.postLoginUrl),
276
- user_data: Object.values(user.data).some(f => f !== null && f !== undefined) ? user.data : {} // Include user.data if at least one field is defined
277
-
278
- }; // Set the user_id to the application's default user id format if it is defined
279
-
280
- if ((_app$config3 = app.config) !== null && _app$config3 !== void 0 && _app$config3.default_user_id_format) {
281
- var _app$config4;
282
-
283
- payload.user_id = (_app$config4 = app.config) === null || _app$config4 === void 0 ? void 0 : _app$config4.default_user_id_format;
284
- }
285
-
286
- if (requiresAdditionalFields) {
287
- payload.user_data = { ...payload.user_data,
288
- ...addlFieldValues
289
- };
290
- } // Submission
291
-
292
-
293
- try {
294
- var _payload$fingerprint;
295
-
296
- setIsSubmitting(true); // Get the browser fingerprint for future sign-ins that don't require re-verification
297
-
298
- const fingerprint = await getFingerprint();
299
- const challengeEntry = await getChallengeIfPresent(app.id, [userIdentifier]);
300
- payload.fingerprint = {
301
- hash: fingerprint.visitorId,
302
- challenge: challengeEntry === null || challengeEntry === void 0 ? void 0 : challengeEntry.value
303
- };
304
- const resp = await api.post('hub/auth/init', {
305
- headers: {
306
- 'x-rownd-app-key': config === null || config === void 0 ? void 0 : config.appKey
307
- },
308
- json: payload
309
- }).json(); // This will only be true when a user is signing in for the very first time and
310
- // the app allows unverified users OR the user was successfully fingerprinted.
311
-
312
- if (resp.auth_tokens) {
313
- dispatch({
314
- type: ActionType.LOGIN_SUCCESS,
315
- payload: { ...resp.auth_tokens,
316
- app_id: app.id
317
- }
318
- });
319
- setStep(LoginStep.SUCCESS);
320
- return;
321
- } else if (payload !== null && payload !== void 0 && (_payload$fingerprint = payload.fingerprint) !== null && _payload$fingerprint !== void 0 && _payload$fingerprint.challenge) {
322
- // The fingerprint is probably expired, so delete the challenge for re-registration
323
- try {
324
- clearFingerprint(payload.fingerprint.challenge);
325
- } catch (err) {// no-op, but not likely to throw anyway
326
- }
327
- }
328
-
329
- setRequestId(resp.challenge_id);
330
- setStep(LoginStep.WAITING);
331
- setLoginPollStart(Date.now());
332
- } catch (err) {
333
- // logger.error(err);
334
- if (err.response.status === 400) {
335
- setStep(LoginStep.INIT);
336
- setRequiresAdditionalFields(true);
337
- return;
338
- }
339
-
340
- setStep(LoginStep.ERROR);
341
- setError(err.message);
342
- } finally {
343
- setIsSubmitting(false);
344
- }
345
- }, [step, fieldError, loginType, userIdentifier, nav === null || nav === void 0 ? void 0 : (_nav$options10 = nav.options) === null || _nav$options10 === void 0 ? void 0 : _nav$options10.post_login_redirect, (_state$config5 = state.config) === null || _state$config5 === void 0 ? void 0 : _state$config5.postLoginUrl, user.data, (_app$config5 = app.config) === null || _app$config5 === void 0 ? void 0 : _app$config5.default_user_id_format, app.id, requiresAdditionalFields, addlFieldValues, getFingerprint, getChallengeIfPresent, api, config === null || config === void 0 ? void 0 : config.appKey, dispatch, clearFingerprint]);
346
-
347
- const launchRowndWebsite = () => {
348
- Linking.openURL('https://rownd.io');
349
- };
350
-
351
- const handleAddlFieldChange = evt => {
352
- const target = evt.target;
353
- const {
354
- value,
355
- name
356
- } = target;
357
- addlFieldDispatch({
358
- type: 'default',
359
- payload: {
360
- [name]: value
361
- }
362
- });
363
- };
364
-
365
- const handleClose = useCallback(() => {
366
- setTimeout(() => {
367
- navTo({
368
- hide: true
369
- });
370
- }, 150);
371
- }, [navTo]);
372
- const snapPoints = useMemo(() => ['25%', '70%'], []);
373
- const renderBackdrop = useCallback(cbProps => /*#__PURE__*/React.createElement(BottomSheetBackdrop, _extends({}, cbProps, {
374
- pressBehavior: "close"
375
- })), []);
376
- let extraBottomSheetProps = {};
377
-
378
- if (bottomSheetMeta.version.startsWith('4')) {
379
- var _state$nav, _state$nav$options;
380
-
381
- extraBottomSheetProps.keyboardBehavior = 'fillParent';
382
- extraBottomSheetProps.android_keyboardInputMode = 'adjustResize';
383
- extraBottomSheetProps.enablePanDownToClose = (state === null || state === void 0 ? void 0 : (_state$nav = state.nav) === null || _state$nav === void 0 ? void 0 : (_state$nav$options = _state$nav.options) === null || _state$nav$options === void 0 ? void 0 : _state$nav$options.type) === 'error';
384
- }
385
-
386
- return /*#__PURE__*/React.createElement(BottomSheetModal, _extends({
387
- snapPoints: snapPoints,
388
- index: 1,
389
- backdropComponent: renderBackdrop,
390
- onDismiss: handleClose,
391
- style: styles.bottomSheet,
392
- ref: bottomSheetModalRef
393
- }, extraBottomSheetProps), /*#__PURE__*/React.createElement(View, {
394
- style: styles.innerContainer
395
- }, step === LoginStep.INIT && /*#__PURE__*/React.createElement(React.Fragment, null, (app === null || app === void 0 ? void 0 : (_app$config6 = app.config) === null || _app$config6 === void 0 ? void 0 : (_app$config6$hub = _app$config6.hub) === null || _app$config6$hub === void 0 ? void 0 : (_app$config6$hub$auth = _app$config6$hub.auth) === null || _app$config6$hub$auth === void 0 ? void 0 : _app$config6$hub$auth.show_app_icon) && (app === null || app === void 0 ? void 0 : app.icon) && (app.icon_content_type === 'image/svg+xml' ? /*#__PURE__*/React.createElement(SvgCssUri, {
396
- uri: app.icon,
397
- style: styles.appLogo
398
- }) : /*#__PURE__*/React.createElement(Image, {
399
- style: styles.appLogo,
400
- source: {
401
- uri: app.icon
402
- }
403
- })), /*#__PURE__*/React.createElement(Text, {
404
- style: styles.dialogHeading
405
- }, "Sign in or sign up"), /*#__PURE__*/React.createElement(Text, {
406
- style: styles.inputLabel
407
- }, "Email or phone number"), /*#__PURE__*/React.createElement(BottomSheetTextInput, {
408
- style: styles.identifierInput,
409
- placeholder: "Enter here",
410
- keyboardType: "email-address",
411
- textContentType: "emailAddress",
412
- returnKeyLabel: "Sign in",
413
- returnKeyType: "go",
414
- enablesReturnKeyAutomatically: true,
415
- autoCapitalize: "none",
416
- onChangeText: text => setUserIdentifier(text.trim()),
417
- onBlur: validateInput // value={userIdentifier} // managed inputs that modify values cause strange issues on Android :-(
418
- ,
419
- onSubmitEditing: initSignIn,
420
- autoCorrect: false
421
- }), requiresAdditionalFields && (app === null || app === void 0 ? void 0 : (_app$config7 = app.config) === null || _app$config7 === void 0 ? void 0 : (_app$config7$hub = _app$config7.hub) === null || _app$config7$hub === void 0 ? void 0 : (_app$config7$hub$auth = _app$config7$hub.auth) === null || _app$config7$hub$auth === void 0 ? void 0 : _app$config7$hub$auth.additional_fields.map(field => {
422
- return renderField({ ...field,
423
- value: addlFieldValues[field.name] || '',
424
- [['input', 'text', 'tel', 'email'].includes(field.type) ? 'onInput' : 'onChange']: handleAddlFieldChange
425
- });
426
- })), /*#__PURE__*/React.createElement(TouchableOpacity, {
427
- disabled: !isValidUserIdentifier || isSubmitting,
428
- onPress: initSignIn
429
- }, /*#__PURE__*/React.createElement(View, {
430
- style: { ...styles.button,
431
- ...(!isValidUserIdentifier && styles.buttonDisabled),
432
- ...(isSubmitting && styles.buttonSubmitting)
433
- }
434
- }, /*#__PURE__*/React.createElement(View, {
435
- style: styles.buttonText
436
- }, /*#__PURE__*/React.createElement(Text, {
437
- style: isValidUserIdentifier ? styles.buttonContent : { ...styles.buttonContent,
438
- ...styles.buttonDisabledText
439
- }
440
- }, isSubmitting &&
441
- /*#__PURE__*/
442
- // <View width={25} height={25}>
443
- React.createElement(ActivityIndicator, {
444
- size: "small",
445
- color: "#efefef",
446
- style: styles.loadingIndicator
447
- }) // </View>
448
- , isSubmitting ? 'Just a sec...' : 'Continue')))), /*#__PURE__*/React.createElement(Text, {
449
- style: styles.signInNoticeText
450
- }, "By continuing, you're agreeing to the terms of service that govern this app and to receive email or text messages for verification purposes.")), step === LoginStep.WAITING && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
451
- style: styles.dialogHeading
452
- }, "Thanks! Verify your", ' ', loginType === 'phone' ? 'phone number' : 'email', " to finish"), /*#__PURE__*/React.createElement(Text, {
453
- style: styles.py6
454
- }, "Click the link in the message we just sent to", ' ', /*#__PURE__*/React.createElement(Text, {
455
- style: styles.italic
456
- }, userIdentifier), " to verify and finish.", /*#__PURE__*/React.createElement(Text, {
457
- style: [styles.link],
458
- onPress: () => setStep(LoginStep.INIT)
459
- }, "\xA0Re-send message")), /*#__PURE__*/React.createElement(View, {
460
- style: styles.signInVerificationImage
461
- }, loginType === 'phone' ? /*#__PURE__*/React.createElement(ImagePhoneVerifyWaiting, null) : /*#__PURE__*/React.createElement(ImageEmailVerifyWaiting, null)), /*#__PURE__*/React.createElement(TouchableOpacity, {
462
- style: [styles.button],
463
- onPress: () => setStep(LoginStep.INIT)
464
- }, /*#__PURE__*/React.createElement(Text, {
465
- style: styles.buttonContent
466
- }, "Try a different", ' ', loginType === 'phone' ? 'phone number' : 'email'))), step === LoginStep.SUCCESS && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
467
- style: styles.signInVerificationImage
468
- }, /*#__PURE__*/React.createElement(ImageCheckmarkFilled, null))), step === LoginStep.FAILURE && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
469
- style: styles.textBase
470
- }, "Whoops, that didn't work!"), /*#__PURE__*/React.createElement(TouchableOpacity, {
471
- style: styles.button,
472
- onPress: () => setStep(LoginStep.INIT)
473
- }, /*#__PURE__*/React.createElement(Text, {
474
- style: styles.buttonContent
475
- }, "Try again"))), step === LoginStep.ERROR && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
476
- style: styles.textBase
477
- }, "An error occurred while signing you in."), !!error && /*#__PURE__*/React.createElement(Text, {
478
- style: styles.textRose800
479
- }, error), /*#__PURE__*/React.createElement(TouchableOpacity, {
480
- style: styles.button,
481
- onPress: () => setStep(LoginStep.INIT)
482
- }, /*#__PURE__*/React.createElement(Text, {
483
- style: styles.buttonContent
484
- }, "Try again"))), /*#__PURE__*/React.createElement(Text, null, "Powered by", ' ', /*#__PURE__*/React.createElement(Text, {
485
- style: styles.link,
486
- onPress: launchRowndWebsite
487
- }, "Rownd"))));
488
- }
489
- const styles = StyleSheet.create({
490
- modal: {// flex: 1,
491
- },
492
- bottomSheet: {
493
- shadowColor: '#000',
494
- shadowOffset: {
495
- width: 0,
496
- height: 12
497
- },
498
- shadowOpacity: 0.58,
499
- shadowRadius: 16.0,
500
- elevation: 24
501
- },
502
- innerContainer: {
503
- borderRadius: 20,
504
- borderColor: 'transparent',
505
- borderWidth: 0,
506
- padding: 25
507
- },
508
- container: {
509
- flex: 1,
510
- padding: 24
511
- },
512
- header: {
513
- alignItems: 'center',
514
- backgroundColor: 'white',
515
- paddingVertical: 20,
516
- borderTopLeftRadius: 20,
517
- borderTopRightRadius: 20
518
- },
519
- panelHandle: {
520
- width: 40,
521
- height: 2,
522
- backgroundColor: 'rgba(0,0,0,0.3)',
523
- borderRadius: 4
524
- },
525
- appLogo: {
526
- padding: 50,
527
- width: 75,
528
- height: 75,
529
- resizeMode: 'center',
530
- textAlign: 'center',
531
- marginLeft: 'auto',
532
- marginRight: 'auto',
533
- marginBottom: 20
534
- },
535
- dialogHeading: {
536
- fontSize: 24
537
- },
538
- inputLabel: {
539
- marginTop: 20,
540
- marginBottom: 5
541
- },
542
- identifierInput: {
543
- backgroundColor: '#eee',
544
- borderRadius: 8,
545
- padding: 10,
546
- fontSize: 18
547
- },
548
- button: {
549
- borderRadius: 10,
550
- padding: 10,
551
- marginTop: 20,
552
- marginBottom: 30,
553
- elevation: 0,
554
- backgroundColor: '#5b0ae0',
555
- color: '#fff',
556
- display: 'flex',
557
- alignItems: 'center',
558
- justifyContent: 'center' // height: 45,
559
-
560
- },
561
- buttonDisabled: {
562
- backgroundColor: '#eee'
563
- },
564
- buttonPressed: {
565
- opacity: 0.5
566
- },
567
- buttonContent: {
568
- textAlign: 'center',
569
- fontSize: 18,
570
- color: '#fff'
571
- },
572
- buttonText: {// marginHorizontal: 10,
573
- // paddingHorizontal: 10,
574
- // fontSize: 18,
575
- // color: '#fff',
576
- },
577
- buttonTextInner: {
578
- fontSize: 18
579
- },
580
- buttonDisabledText: {
581
- color: '#8e8e8e'
582
- },
583
- buttonSubmitting: {
584
- backgroundColor: '#2f0492',
585
- color: '#c7c7c7'
586
- },
587
- loadingIndicator: {
588
- marginRight: 10,
589
- width: 25,
590
- height: 25
591
- },
592
- signInNoticeText: {
593
- fontSize: 12,
594
- marginBottom: 20
595
- },
596
- signInVerificationImage: {
597
- alignItems: 'center'
598
- },
599
- link: {
600
- color: '#6114e1'
601
- },
602
- py6: {
603
- paddingVertical: 6
604
- },
605
- italic: {
606
- fontStyle: 'italic'
607
- },
608
- textBase: {
609
- fontSize: 16,
610
- lineHeight: 24
611
- },
612
- textRose800: {
613
- color: 'rgb(159, 18, 57)'
614
- }
615
- });
616
- //# sourceMappingURL=SignIn.js.map