@rownd/react-native 0.2.4 → 2.1.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 (253) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -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/Rownd.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  10. package/ios/RowndPlugin-Bridging-Header.h +3 -0
  11. package/ios/RowndPlugin.m +26 -0
  12. package/ios/RowndPlugin.swift +83 -0
  13. package/ios/RowndPluginEventEmitter.m +12 -0
  14. package/ios/RowndPluginEventEmitter.swift +19 -0
  15. package/lib/commonjs/components/GlobalContext.js +30 -298
  16. package/lib/commonjs/components/GlobalContext.js.map +1 -1
  17. package/lib/commonjs/components/{BottomSheetTextInput/types.js → GlobalContext.types.js} +1 -1
  18. package/lib/commonjs/components/GlobalContext.types.js.map +1 -0
  19. package/lib/commonjs/constants/action.js +13 -0
  20. package/lib/commonjs/constants/action.js.map +1 -0
  21. package/lib/commonjs/hooks/rownd.js +15 -146
  22. package/lib/commonjs/hooks/rownd.js.map +1 -1
  23. package/lib/commonjs/index.js +2 -12
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/reducer/rowndReducer.js +89 -0
  26. package/lib/commonjs/reducer/rowndReducer.js.map +1 -0
  27. package/lib/commonjs/utils/config.js +0 -26
  28. package/lib/commonjs/utils/config.js.map +1 -1
  29. package/lib/commonjs/utils/nativeModule.js +72 -0
  30. package/lib/commonjs/utils/nativeModule.js.map +1 -0
  31. package/lib/module/components/GlobalContext.js +29 -293
  32. package/lib/module/components/GlobalContext.js.map +1 -1
  33. package/lib/module/components/GlobalContext.types.js +2 -0
  34. package/lib/module/components/GlobalContext.types.js.map +1 -0
  35. package/lib/module/constants/action.js +6 -0
  36. package/lib/module/constants/action.js.map +1 -0
  37. package/lib/module/hooks/rownd.js +12 -137
  38. package/lib/module/hooks/rownd.js.map +1 -1
  39. package/lib/module/index.js +2 -4
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/module/reducer/rowndReducer.js +78 -0
  42. package/lib/module/reducer/rowndReducer.js.map +1 -0
  43. package/lib/module/utils/config.js +1 -16
  44. package/lib/module/utils/config.js.map +1 -1
  45. package/lib/module/utils/nativeModule.js +48 -0
  46. package/lib/module/utils/nativeModule.js.map +1 -0
  47. package/lib/typescript/components/GlobalContext.d.ts +13 -0
  48. package/lib/typescript/{src/components/GlobalContext.d.ts → components/GlobalContext.types.d.ts} +9 -35
  49. package/lib/typescript/constants/action.d.ts +7 -0
  50. package/lib/typescript/{src/hooks → hooks}/rownd.d.ts +10 -13
  51. package/lib/typescript/index.d.ts +3 -0
  52. package/lib/typescript/reducer/rowndReducer.d.ts +4 -0
  53. package/lib/typescript/utils/config.d.ts +10 -0
  54. package/lib/typescript/utils/nativeModule.d.ts +10 -0
  55. package/package.json +36 -56
  56. package/rownd-react-native.podspec +36 -0
  57. package/src/components/GlobalContext.tsx +44 -457
  58. package/src/components/GlobalContext.types.ts +105 -0
  59. package/src/constants/action.ts +8 -0
  60. package/src/hooks/rownd.ts +29 -147
  61. package/src/index.tsx +2 -4
  62. package/src/reducer/rowndReducer.ts +78 -0
  63. package/src/utils/config.ts +0 -27
  64. package/src/utils/nativeModule.ts +69 -0
  65. package/android/src/main/java/com/reactnative/ReactNativePackage.java +0 -22
  66. package/android/src/main/java/com/reactnative/ReactNativeViewManager.java +0 -31
  67. package/ios/ReactNativeViewManager.m +0 -34
  68. package/lib/commonjs/assets/images/checkmark--filled.svg +0 -12
  69. package/lib/commonjs/assets/images/email-verify-waiting.svg +0 -36
  70. package/lib/commonjs/assets/images/error-icon-material.svg +0 -1
  71. package/lib/commonjs/assets/images/phone-verify-waiting.svg +0 -26
  72. package/lib/commonjs/components/AuthenticatedComponent.js +0 -35
  73. package/lib/commonjs/components/AuthenticatedComponent.js.map +0 -1
  74. package/lib/commonjs/components/AutoSigninDialog.js +0 -132
  75. package/lib/commonjs/components/AutoSigninDialog.js.map +0 -1
  76. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -65
  77. package/lib/commonjs/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  78. package/lib/commonjs/components/BottomSheetTextInput/index.js +0 -24
  79. package/lib/commonjs/components/BottomSheetTextInput/index.js.map +0 -1
  80. package/lib/commonjs/components/BottomSheetTextInput/types.js.map +0 -1
  81. package/lib/commonjs/components/DarkText.js +0 -35
  82. package/lib/commonjs/components/DarkText.js.map +0 -1
  83. package/lib/commonjs/components/DefaultContext.js +0 -266
  84. package/lib/commonjs/components/DefaultContext.js.map +0 -1
  85. package/lib/commonjs/components/RowndComponents.js +0 -25
  86. package/lib/commonjs/components/RowndComponents.js.map +0 -1
  87. package/lib/commonjs/components/RowndProvider.js +0 -55
  88. package/lib/commonjs/components/RowndProvider.js.map +0 -1
  89. package/lib/commonjs/components/SignIn.js +0 -638
  90. package/lib/commonjs/components/SignIn.js.map +0 -1
  91. package/lib/commonjs/components/images/CheckmarkFilled.js +0 -40
  92. package/lib/commonjs/components/images/CheckmarkFilled.js.map +0 -1
  93. package/lib/commonjs/components/images/EmailVerifyWaiting.js +0 -100
  94. package/lib/commonjs/components/images/EmailVerifyWaiting.js.map +0 -1
  95. package/lib/commonjs/components/images/ErrorIcon.js +0 -31
  96. package/lib/commonjs/components/images/ErrorIcon.js.map +0 -1
  97. package/lib/commonjs/components/images/PhoneVerifyWaiting.js +0 -91
  98. package/lib/commonjs/components/images/PhoneVerifyWaiting.js.map +0 -1
  99. package/lib/commonjs/data/actions.js +0 -26
  100. package/lib/commonjs/data/actions.js.map +0 -1
  101. package/lib/commonjs/hooks/api.js +0 -155
  102. package/lib/commonjs/hooks/api.js.map +0 -1
  103. package/lib/commonjs/hooks/debounce.js +0 -38
  104. package/lib/commonjs/hooks/debounce.js.map +0 -1
  105. package/lib/commonjs/hooks/fingerprint.js +0 -176
  106. package/lib/commonjs/hooks/fingerprint.js.map +0 -1
  107. package/lib/commonjs/hooks/index.js +0 -48
  108. package/lib/commonjs/hooks/index.js.map +0 -1
  109. package/lib/commonjs/hooks/interval.js +0 -31
  110. package/lib/commonjs/hooks/interval.js.map +0 -1
  111. package/lib/commonjs/hooks/nav.js +0 -39
  112. package/lib/commonjs/hooks/nav.js.map +0 -1
  113. package/lib/commonjs/index.tsx.bak +0 -26
  114. package/lib/commonjs/types.js +0 -2
  115. package/lib/commonjs/types.js.map +0 -1
  116. package/lib/commonjs/utils/events.js +0 -57
  117. package/lib/commonjs/utils/events.js.map +0 -1
  118. package/lib/commonjs/utils/form.js +0 -46
  119. package/lib/commonjs/utils/form.js.map +0 -1
  120. package/lib/commonjs/utils/queue.js +0 -117
  121. package/lib/commonjs/utils/queue.js.map +0 -1
  122. package/lib/commonjs/utils/storage.js +0 -15
  123. package/lib/commonjs/utils/storage.js.map +0 -1
  124. package/lib/commonjs/utils/tokens.js +0 -35
  125. package/lib/commonjs/utils/tokens.js.map +0 -1
  126. package/lib/commonjs/utils/user-data.js +0 -21
  127. package/lib/commonjs/utils/user-data.js.map +0 -1
  128. package/lib/module/assets/images/checkmark--filled.svg +0 -12
  129. package/lib/module/assets/images/email-verify-waiting.svg +0 -36
  130. package/lib/module/assets/images/error-icon-material.svg +0 -1
  131. package/lib/module/assets/images/phone-verify-waiting.svg +0 -26
  132. package/lib/module/components/AuthenticatedComponent.js +0 -24
  133. package/lib/module/components/AuthenticatedComponent.js.map +0 -1
  134. package/lib/module/components/AutoSigninDialog.js +0 -110
  135. package/lib/module/components/AutoSigninDialog.js.map +0 -1
  136. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js +0 -52
  137. package/lib/module/components/BottomSheetTextInput/BottomSheetTextInput.js.map +0 -1
  138. package/lib/module/components/BottomSheetTextInput/index.js +0 -5
  139. package/lib/module/components/BottomSheetTextInput/index.js.map +0 -1
  140. package/lib/module/components/BottomSheetTextInput/types.js +0 -2
  141. package/lib/module/components/BottomSheetTextInput/types.js.map +0 -1
  142. package/lib/module/components/DarkText.js +0 -24
  143. package/lib/module/components/DarkText.js.map +0 -1
  144. package/lib/module/components/DefaultContext.js +0 -244
  145. package/lib/module/components/DefaultContext.js.map +0 -1
  146. package/lib/module/components/RowndComponents.js +0 -12
  147. package/lib/module/components/RowndComponents.js.map +0 -1
  148. package/lib/module/components/RowndProvider.js +0 -39
  149. package/lib/module/components/RowndProvider.js.map +0 -1
  150. package/lib/module/components/SignIn.js +0 -610
  151. package/lib/module/components/SignIn.js.map +0 -1
  152. package/lib/module/components/images/CheckmarkFilled.js +0 -27
  153. package/lib/module/components/images/CheckmarkFilled.js.map +0 -1
  154. package/lib/module/components/images/EmailVerifyWaiting.js +0 -87
  155. package/lib/module/components/images/EmailVerifyWaiting.js.map +0 -1
  156. package/lib/module/components/images/ErrorIcon.js +0 -18
  157. package/lib/module/components/images/ErrorIcon.js.map +0 -1
  158. package/lib/module/components/images/PhoneVerifyWaiting.js +0 -78
  159. package/lib/module/components/images/PhoneVerifyWaiting.js.map +0 -1
  160. package/lib/module/data/actions.js +0 -19
  161. package/lib/module/data/actions.js.map +0 -1
  162. package/lib/module/hooks/api.js +0 -135
  163. package/lib/module/hooks/api.js.map +0 -1
  164. package/lib/module/hooks/debounce.js +0 -29
  165. package/lib/module/hooks/debounce.js.map +0 -1
  166. package/lib/module/hooks/fingerprint.js +0 -157
  167. package/lib/module/hooks/fingerprint.js.map +0 -1
  168. package/lib/module/hooks/index.js +0 -7
  169. package/lib/module/hooks/index.js.map +0 -1
  170. package/lib/module/hooks/interval.js +0 -23
  171. package/lib/module/hooks/interval.js.map +0 -1
  172. package/lib/module/hooks/nav.js +0 -30
  173. package/lib/module/hooks/nav.js.map +0 -1
  174. package/lib/module/index.tsx.bak +0 -26
  175. package/lib/module/types.js +0 -2
  176. package/lib/module/types.js.map +0 -1
  177. package/lib/module/utils/events.js +0 -45
  178. package/lib/module/utils/events.js.map +0 -1
  179. package/lib/module/utils/form.js +0 -34
  180. package/lib/module/utils/form.js.map +0 -1
  181. package/lib/module/utils/queue.js +0 -109
  182. package/lib/module/utils/queue.js.map +0 -1
  183. package/lib/module/utils/storage.js +0 -6
  184. package/lib/module/utils/storage.js.map +0 -1
  185. package/lib/module/utils/tokens.js +0 -24
  186. package/lib/module/utils/tokens.js.map +0 -1
  187. package/lib/module/utils/user-data.js +0 -14
  188. package/lib/module/utils/user-data.js.map +0 -1
  189. package/lib/package.json +0 -173
  190. package/lib/typescript/src/components/AuthenticatedComponent.d.ts +0 -7
  191. package/lib/typescript/src/components/AutoSigninDialog.d.ts +0 -2
  192. package/lib/typescript/src/components/BottomSheetTextInput/BottomSheetTextInput.d.ts +0 -4
  193. package/lib/typescript/src/components/BottomSheetTextInput/index.d.ts +0 -2
  194. package/lib/typescript/src/components/BottomSheetTextInput/types.d.ts +0 -3
  195. package/lib/typescript/src/components/DarkText.d.ts +0 -3
  196. package/lib/typescript/src/components/DefaultContext.d.ts +0 -12
  197. package/lib/typescript/src/components/RowndComponents.d.ts +0 -2
  198. package/lib/typescript/src/components/RowndProvider.d.ts +0 -8
  199. package/lib/typescript/src/components/SignIn.d.ts +0 -2
  200. package/lib/typescript/src/components/images/CheckmarkFilled.d.ts +0 -4
  201. package/lib/typescript/src/components/images/EmailVerifyWaiting.d.ts +0 -4
  202. package/lib/typescript/src/components/images/ErrorIcon.d.ts +0 -4
  203. package/lib/typescript/src/components/images/PhoneVerifyWaiting.d.ts +0 -4
  204. package/lib/typescript/src/data/actions.d.ts +0 -20
  205. package/lib/typescript/src/hooks/api.d.ts +0 -12
  206. package/lib/typescript/src/hooks/debounce.d.ts +0 -5
  207. package/lib/typescript/src/hooks/fingerprint.d.ts +0 -12
  208. package/lib/typescript/src/hooks/index.d.ts +0 -6
  209. package/lib/typescript/src/hooks/interval.d.ts +0 -2
  210. package/lib/typescript/src/hooks/nav.d.ts +0 -6
  211. package/lib/typescript/src/index.d.ts +0 -4
  212. package/lib/typescript/src/types.d.ts +0 -26
  213. package/lib/typescript/src/utils/config.d.ts +0 -18
  214. package/lib/typescript/src/utils/events.d.ts +0 -22
  215. package/lib/typescript/src/utils/form.d.ts +0 -18
  216. package/lib/typescript/src/utils/queue.d.ts +0 -21
  217. package/lib/typescript/src/utils/storage.d.ts +0 -3
  218. package/lib/typescript/src/utils/tokens.d.ts +0 -4
  219. package/lib/typescript/src/utils/user-data.d.ts +0 -3
  220. package/react-native.podspec +0 -19
  221. package/src/assets/images/checkmark--filled.svg +0 -12
  222. package/src/assets/images/email-verify-waiting.svg +0 -36
  223. package/src/assets/images/error-icon-material.svg +0 -1
  224. package/src/assets/images/phone-verify-waiting.svg +0 -26
  225. package/src/components/AuthenticatedComponent.tsx +0 -30
  226. package/src/components/AutoSigninDialog.tsx +0 -131
  227. package/src/components/BottomSheetTextInput/BottomSheetTextInput.tsx +0 -57
  228. package/src/components/BottomSheetTextInput/index.ts +0 -5
  229. package/src/components/BottomSheetTextInput/types.ts +0 -3
  230. package/src/components/DarkText.tsx +0 -16
  231. package/src/components/DefaultContext.tsx +0 -278
  232. package/src/components/RowndComponents.tsx +0 -18
  233. package/src/components/RowndProvider.tsx +0 -56
  234. package/src/components/SignIn.tsx +0 -793
  235. package/src/components/images/CheckmarkFilled.tsx +0 -30
  236. package/src/components/images/EmailVerifyWaiting.tsx +0 -95
  237. package/src/components/images/ErrorIcon.tsx +0 -11
  238. package/src/components/images/PhoneVerifyWaiting.tsx +0 -74
  239. package/src/data/actions.ts +0 -21
  240. package/src/hooks/api.ts +0 -162
  241. package/src/hooks/debounce.ts +0 -36
  242. package/src/hooks/fingerprint.ts +0 -217
  243. package/src/hooks/index.ts +0 -7
  244. package/src/hooks/interval.ts +0 -25
  245. package/src/hooks/nav.tsx +0 -29
  246. package/src/index.tsx.bak +0 -26
  247. package/src/types.ts +0 -27
  248. package/src/utils/events.ts +0 -54
  249. package/src/utils/form.tsx +0 -64
  250. package/src/utils/queue.ts +0 -75
  251. package/src/utils/storage.ts +0 -7
  252. package/src/utils/tokens.ts +0 -26
  253. package/src/utils/user-data.ts +0 -15
@@ -1,610 +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}
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 && /*#__PURE__*/React.createElement(ActivityIndicator, {
441
- size: "small",
442
- color: "#efefef",
443
- style: styles.loadingIndicator
444
- }), isSubmitting ? 'Just a sec...' : 'Continue')))), /*#__PURE__*/React.createElement(Text, {
445
- style: styles.signInNoticeText
446
- }, "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, {
447
- style: styles.dialogHeading
448
- }, "Thanks! Verify your", ' ', loginType === 'phone' ? 'phone number' : 'email', " to finish"), /*#__PURE__*/React.createElement(Text, {
449
- style: styles.py6
450
- }, "Click the link in the message we just sent to", ' ', /*#__PURE__*/React.createElement(Text, {
451
- style: styles.italic
452
- }, userIdentifier), " to verify and finish.", /*#__PURE__*/React.createElement(Text, {
453
- style: [styles.link],
454
- onPress: () => setStep(LoginStep.INIT)
455
- }, "\xA0Re-send message")), /*#__PURE__*/React.createElement(View, {
456
- style: styles.signInVerificationImage
457
- }, loginType === 'phone' ? /*#__PURE__*/React.createElement(ImagePhoneVerifyWaiting, null) : /*#__PURE__*/React.createElement(ImageEmailVerifyWaiting, null)), /*#__PURE__*/React.createElement(TouchableOpacity, {
458
- style: [styles.button],
459
- onPress: () => setStep(LoginStep.INIT)
460
- }, /*#__PURE__*/React.createElement(Text, {
461
- style: styles.buttonContent
462
- }, "Try a different", ' ', loginType === 'phone' ? 'phone number' : 'email'))), step === LoginStep.SUCCESS && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
463
- style: styles.signInVerificationImage
464
- }, /*#__PURE__*/React.createElement(ImageCheckmarkFilled, null))), step === LoginStep.FAILURE && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
465
- style: styles.textBase
466
- }, "Whoops, that didn't work!"), /*#__PURE__*/React.createElement(TouchableOpacity, {
467
- style: styles.button,
468
- onPress: () => setStep(LoginStep.INIT)
469
- }, /*#__PURE__*/React.createElement(Text, {
470
- style: styles.buttonContent
471
- }, "Try again"))), step === LoginStep.ERROR && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Text, {
472
- style: styles.textBase
473
- }, "An error occurred while signing you in."), !!error && /*#__PURE__*/React.createElement(Text, {
474
- style: styles.textRose800
475
- }, error), /*#__PURE__*/React.createElement(TouchableOpacity, {
476
- style: styles.button,
477
- onPress: () => setStep(LoginStep.INIT)
478
- }, /*#__PURE__*/React.createElement(Text, {
479
- style: styles.buttonContent
480
- }, "Try again"))), /*#__PURE__*/React.createElement(Text, null, "Powered by", ' ', /*#__PURE__*/React.createElement(Text, {
481
- style: styles.link,
482
- onPress: launchRowndWebsite
483
- }, "Rownd"))));
484
- }
485
- const styles = StyleSheet.create({
486
- modal: {// flex: 1,
487
- },
488
- bottomSheet: {
489
- shadowColor: '#000',
490
- shadowOffset: {
491
- width: 0,
492
- height: 12
493
- },
494
- shadowOpacity: 0.58,
495
- shadowRadius: 16.0,
496
- elevation: 24
497
- },
498
- innerContainer: {
499
- borderRadius: 20,
500
- borderColor: 'transparent',
501
- borderWidth: 0,
502
- padding: 25
503
- },
504
- container: {
505
- flex: 1,
506
- padding: 24
507
- },
508
- header: {
509
- alignItems: 'center',
510
- backgroundColor: 'white',
511
- paddingVertical: 20,
512
- borderTopLeftRadius: 20,
513
- borderTopRightRadius: 20
514
- },
515
- panelHandle: {
516
- width: 40,
517
- height: 2,
518
- backgroundColor: 'rgba(0,0,0,0.3)',
519
- borderRadius: 4
520
- },
521
- appLogo: {
522
- padding: 50,
523
- width: 75,
524
- height: 75,
525
- resizeMode: 'center',
526
- textAlign: 'center',
527
- marginLeft: 'auto',
528
- marginRight: 'auto',
529
- marginBottom: 20
530
- },
531
- dialogHeading: {
532
- fontSize: 24
533
- },
534
- inputLabel: {
535
- marginTop: 20,
536
- marginBottom: 5
537
- },
538
- identifierInput: {
539
- backgroundColor: '#eee',
540
- borderRadius: 8,
541
- padding: 10,
542
- fontSize: 18
543
- },
544
- button: {
545
- borderRadius: 10,
546
- padding: 10,
547
- marginTop: 20,
548
- marginBottom: 30,
549
- elevation: 0,
550
- backgroundColor: '#5b0ae0',
551
- color: '#fff',
552
- display: 'flex',
553
- alignItems: 'center',
554
- justifyContent: 'center' // height: 45,
555
-
556
- },
557
- buttonDisabled: {
558
- backgroundColor: '#eee'
559
- },
560
- buttonPressed: {
561
- opacity: 0.5
562
- },
563
- buttonContent: {
564
- textAlign: 'center',
565
- fontSize: 18,
566
- color: '#fff'
567
- },
568
- buttonText: {// marginHorizontal: 10,
569
- // paddingHorizontal: 10,
570
- // fontSize: 18,
571
- // color: '#fff',
572
- },
573
- buttonTextInner: {
574
- fontSize: 18
575
- },
576
- buttonDisabledText: {
577
- color: '#8e8e8e'
578
- },
579
- buttonSubmitting: {
580
- backgroundColor: '#2f0492',
581
- color: '#c7c7c7'
582
- },
583
- loadingIndicator: {
584
- marginRight: 10
585
- },
586
- signInNoticeText: {
587
- fontSize: 12,
588
- marginBottom: 20
589
- },
590
- signInVerificationImage: {
591
- alignItems: 'center'
592
- },
593
- link: {
594
- color: '#6114e1'
595
- },
596
- py6: {
597
- paddingVertical: 6
598
- },
599
- italic: {
600
- fontStyle: 'italic'
601
- },
602
- textBase: {
603
- fontSize: 16,
604
- lineHeight: 24
605
- },
606
- textRose800: {
607
- color: 'rgb(159, 18, 57)'
608
- }
609
- });
610
- //# sourceMappingURL=SignIn.js.map