@supertokens/rownd-react-native 0.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 (106) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +554 -0
  3. package/android/build.gradle +153 -0
  4. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  6. package/android/gradle.properties +5 -0
  7. package/android/gradlew +234 -0
  8. package/android/gradlew.bat +89 -0
  9. package/android/src/main/AndroidManifest.xml +4 -0
  10. package/android/src/main/java/com/reactnativerowndplugin/RowndPluginModule.kt +235 -0
  11. package/android/src/main/java/com/reactnativerowndplugin/RowndPluginPackage.kt +25 -0
  12. package/app.plugin.js +3 -0
  13. package/expo/plugin.js +61 -0
  14. package/ios/Rownd.xcodeproj/project.pbxproj +283 -0
  15. package/ios/RowndHelper.swift +62 -0
  16. package/ios/RowndPlugin-Bridging-Header.h +3 -0
  17. package/ios/RowndPlugin.m +31 -0
  18. package/ios/RowndPlugin.swift +233 -0
  19. package/ios/RowndPluginEventEmitter.m +12 -0
  20. package/ios/RowndPluginEventEmitter.swift +19 -0
  21. package/lib/commonjs/components/GlobalContext.js +72 -0
  22. package/lib/commonjs/components/GlobalContext.js.map +1 -0
  23. package/lib/commonjs/components/GlobalContext.types.js +6 -0
  24. package/lib/commonjs/components/GlobalContext.types.js.map +1 -0
  25. package/lib/commonjs/components/GlobalContext.web.js +21 -0
  26. package/lib/commonjs/components/GlobalContext.web.js.map +1 -0
  27. package/lib/commonjs/components/RequireSignIn.js +37 -0
  28. package/lib/commonjs/components/RequireSignIn.js.map +1 -0
  29. package/lib/commonjs/components/SignedIn.js +22 -0
  30. package/lib/commonjs/components/SignedIn.js.map +1 -0
  31. package/lib/commonjs/components/SignedOut.js +22 -0
  32. package/lib/commonjs/components/SignedOut.js.map +1 -0
  33. package/lib/commonjs/constants/action.js +11 -0
  34. package/lib/commonjs/constants/action.js.map +1 -0
  35. package/lib/commonjs/hooks/rownd.js +30 -0
  36. package/lib/commonjs/hooks/rownd.js.map +1 -0
  37. package/lib/commonjs/hooks/rownd.web.js +56 -0
  38. package/lib/commonjs/hooks/rownd.web.js.map +1 -0
  39. package/lib/commonjs/index.js +42 -0
  40. package/lib/commonjs/index.js.map +1 -0
  41. package/lib/commonjs/reducer/rowndReducer.js +67 -0
  42. package/lib/commonjs/reducer/rowndReducer.js.map +1 -0
  43. package/lib/commonjs/types.js +2 -0
  44. package/lib/commonjs/types.js.map +1 -0
  45. package/lib/commonjs/utils/config.js +6 -0
  46. package/lib/commonjs/utils/config.js.map +1 -0
  47. package/lib/commonjs/utils/nativeModule.js +70 -0
  48. package/lib/commonjs/utils/nativeModule.js.map +1 -0
  49. package/lib/module/components/GlobalContext.js +64 -0
  50. package/lib/module/components/GlobalContext.js.map +1 -0
  51. package/lib/module/components/GlobalContext.types.js +2 -0
  52. package/lib/module/components/GlobalContext.types.js.map +1 -0
  53. package/lib/module/components/GlobalContext.web.js +14 -0
  54. package/lib/module/components/GlobalContext.web.js.map +1 -0
  55. package/lib/module/components/RequireSignIn.js +30 -0
  56. package/lib/module/components/RequireSignIn.js.map +1 -0
  57. package/lib/module/components/SignedIn.js +15 -0
  58. package/lib/module/components/SignedIn.js.map +1 -0
  59. package/lib/module/components/SignedOut.js +15 -0
  60. package/lib/module/components/SignedOut.js.map +1 -0
  61. package/lib/module/constants/action.js +5 -0
  62. package/lib/module/constants/action.js.map +1 -0
  63. package/lib/module/hooks/rownd.js +24 -0
  64. package/lib/module/hooks/rownd.js.map +1 -0
  65. package/lib/module/hooks/rownd.web.js +50 -0
  66. package/lib/module/hooks/rownd.web.js.map +1 -0
  67. package/lib/module/index.js +7 -0
  68. package/lib/module/index.js.map +1 -0
  69. package/lib/module/reducer/rowndReducer.js +60 -0
  70. package/lib/module/reducer/rowndReducer.js.map +1 -0
  71. package/lib/module/types.js +2 -0
  72. package/lib/module/types.js.map +1 -0
  73. package/lib/module/utils/config.js +2 -0
  74. package/lib/module/utils/config.js.map +1 -0
  75. package/lib/module/utils/nativeModule.js +55 -0
  76. package/lib/module/utils/nativeModule.js.map +1 -0
  77. package/lib/typescript/components/GlobalContext.d.ts +13 -0
  78. package/lib/typescript/components/GlobalContext.types.d.ts +90 -0
  79. package/lib/typescript/components/GlobalContext.web.d.ts +4 -0
  80. package/lib/typescript/components/RequireSignIn.d.ts +9 -0
  81. package/lib/typescript/components/SignedIn.d.ts +6 -0
  82. package/lib/typescript/components/SignedOut.d.ts +6 -0
  83. package/lib/typescript/constants/action.d.ts +7 -0
  84. package/lib/typescript/hooks/rownd.d.ts +31 -0
  85. package/lib/typescript/hooks/rownd.web.d.ts +2 -0
  86. package/lib/typescript/index.d.ts +6 -0
  87. package/lib/typescript/reducer/rowndReducer.d.ts +4 -0
  88. package/lib/typescript/types.d.ts +21 -0
  89. package/lib/typescript/utils/config.d.ts +7 -0
  90. package/lib/typescript/utils/nativeModule.d.ts +14 -0
  91. package/package.json +167 -0
  92. package/rownd-react-native.podspec +38 -0
  93. package/src/components/GlobalContext.tsx +93 -0
  94. package/src/components/GlobalContext.types.ts +109 -0
  95. package/src/components/GlobalContext.web.tsx +17 -0
  96. package/src/components/RequireSignIn.tsx +35 -0
  97. package/src/components/SignedIn.tsx +17 -0
  98. package/src/components/SignedOut.tsx +17 -0
  99. package/src/constants/action.ts +8 -0
  100. package/src/hooks/rownd.ts +68 -0
  101. package/src/hooks/rownd.web.ts +56 -0
  102. package/src/index.tsx +7 -0
  103. package/src/reducer/rowndReducer.ts +63 -0
  104. package/src/types.ts +32 -0
  105. package/src/utils/config.ts +9 -0
  106. package/src/utils/nativeModule.ts +83 -0
@@ -0,0 +1,109 @@
1
+ import type { TAction } from '../constants/action';
2
+ import type { Customizations, IConfig } from '../utils/config';
3
+
4
+ export type ContextProps = {
5
+ config: IConfig;
6
+ customizations?: Customizations;
7
+ children?: React.ReactNode;
8
+ };
9
+
10
+ export type Dispatch = (action: TAction) => void;
11
+
12
+ export type GlobalState = {
13
+ // is_initializing: boolean;
14
+ // is_container_visible: boolean;
15
+ // use_modal: boolean;
16
+ // nav: {
17
+ // current_route: string;
18
+ // route_trigger: string;
19
+ // event_id: string;
20
+ // section: string;
21
+ // options?: any;
22
+ // };
23
+ user: {
24
+ data: {
25
+ id?: string;
26
+ email?: string | null;
27
+ [key: string]: any;
28
+ };
29
+ isLoading: boolean;
30
+ // needs_refresh?: boolean;
31
+ // redacted: string[];
32
+ };
33
+ auth: {
34
+ access_token: string | null;
35
+ refresh_token?: string | null;
36
+ app_id: string | null;
37
+ init_data?: Record<string, any>;
38
+ is_verified_user?: boolean;
39
+ auth_level?: string | null;
40
+ };
41
+ app: {
42
+ id?: string;
43
+ icon?: string;
44
+ icon_content_type?: string;
45
+ config: AppConfig | null;
46
+ schema: AppSchema | null;
47
+ user_verification_field?: string;
48
+ user_verification_fields?: string[];
49
+ };
50
+ // local_acls: Record<string, { shared: boolean }> | null;
51
+ // is_saving_user_data: boolean;
52
+ config?: IConfig;
53
+ };
54
+
55
+ type AppSchema = Record<string, SchemaField>;
56
+
57
+ export interface SchemaField {
58
+ display_name: string;
59
+ type: string;
60
+ data_category: string;
61
+ required: boolean;
62
+ owned_by: string;
63
+ user_visible: boolean;
64
+ revoke_after: string;
65
+ required_retention: string;
66
+ collection_justification: string;
67
+ opt_out_warning: string;
68
+ }
69
+
70
+ export interface AppConfig {
71
+ customizations: {
72
+ primary_color: string;
73
+ };
74
+ default_user_id_format?: string;
75
+ hub: {
76
+ auth: {
77
+ allow_unverified_users?: boolean;
78
+ additional_fields: [
79
+ {
80
+ name: string;
81
+ type: string;
82
+ label: string;
83
+ placeholder?: string;
84
+ options: [
85
+ {
86
+ value: string;
87
+ label: string;
88
+ }
89
+ ];
90
+ }
91
+ ];
92
+ email: {
93
+ from_address: string;
94
+ image: string;
95
+ };
96
+ show_app_icon: boolean;
97
+ };
98
+ customizations: HubCustomizations;
99
+ };
100
+ }
101
+
102
+ export interface HubCustomizations {
103
+ rounded_corners: boolean;
104
+ primary_color: string;
105
+ placement: 'bottom-left' | 'hidden';
106
+ offset_x: number;
107
+ offset_y: number;
108
+ property_overrides: Record<string, string>;
109
+ }
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import type { ContextProps } from './GlobalContext.types';
3
+ import { RowndProvider as RowndReactProvider } from '@supertokens/rownd-react';
4
+
5
+ const RowndProvider: React.FC<ContextProps> = ({ children, config }) => {
6
+ return (
7
+ <RowndReactProvider
8
+ appKey={config.appKey}
9
+ supertokens={config.supertokens}
10
+ hubUrlOverride={config.hubUrlOverride}
11
+ >
12
+ {children}
13
+ </RowndReactProvider>
14
+ );
15
+ };
16
+
17
+ export { RowndProvider };
@@ -0,0 +1,35 @@
1
+ import React, { useEffect } from 'react';
2
+ import { useRownd } from '../hooks/rownd';
3
+ import type { RequestSignIn } from '../types';
4
+ import { Platform } from 'react-native';
5
+
6
+ export type ContextProps = {
7
+ children?: React.ReactNode;
8
+ initializing?: React.ReactNode;
9
+ signInProps?: RequestSignIn;
10
+ };
11
+
12
+ const RequireSignIn: React.FC<ContextProps> = ({
13
+ children,
14
+ initializing,
15
+ signInProps,
16
+ }) => {
17
+ const { is_authenticated, is_initializing, requestSignIn } = useRownd();
18
+
19
+ useEffect(() => {
20
+ if (!is_authenticated && !is_initializing) {
21
+ requestSignIn({
22
+ ...(Platform.OS === 'web' ? { prevent_closing: true } : undefined),
23
+ ...signInProps,
24
+ });
25
+ }
26
+ }, [is_authenticated, is_initializing, signInProps, requestSignIn]);
27
+
28
+ if (is_initializing && initializing) {
29
+ return <>{initializing}</>;
30
+ }
31
+
32
+ return <>{children}</>;
33
+ };
34
+
35
+ export default RequireSignIn;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { useRownd } from '../hooks/rownd';
3
+
4
+ interface SignedInProps {
5
+ children: React.ReactNode;
6
+ }
7
+
8
+ const SignedIn: React.FC<SignedInProps> = ({ children }) => {
9
+ const { is_authenticated } = useRownd();
10
+
11
+ if (!is_authenticated) {
12
+ return null;
13
+ }
14
+ return <>{children}</>;
15
+ };
16
+
17
+ export default SignedIn;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { useRownd } from '../hooks/rownd';
3
+
4
+ interface SignedOutProps {
5
+ children: React.ReactNode;
6
+ }
7
+
8
+ const SignedOut: React.FC<SignedOutProps> = ({ children }) => {
9
+ const { is_authenticated } = useRownd();
10
+
11
+ if (is_authenticated) {
12
+ return null;
13
+ }
14
+ return <>{children}</>;
15
+ };
16
+
17
+ export default SignedOut;
@@ -0,0 +1,8 @@
1
+ export enum ActionType {
2
+ UPDATE_STATE = 'UPDATE_STATE',
3
+ }
4
+
5
+ export type TAction = {
6
+ type: ActionType;
7
+ payload?: any;
8
+ };
@@ -0,0 +1,68 @@
1
+ import {
2
+ requestSignIn,
3
+ signOut,
4
+ manageAccount,
5
+ getAccessToken,
6
+ setUserDataValue,
7
+ setUserData,
8
+ } from '../utils/nativeModule';
9
+ import { useRowndContext } from '../components/GlobalContext';
10
+ import type {
11
+ RequestSignIn,
12
+ RequestSignInMethods,
13
+ RequestSignInIntent,
14
+ } from '../types';
15
+
16
+ export type { RequestSignIn, RequestSignInMethods, RequestSignInIntent };
17
+
18
+ export type TRowndContext = {
19
+ access_token: string | null;
20
+ auth: AuthContext;
21
+ is_authenticated: boolean;
22
+ is_initializing: boolean;
23
+ getAccessToken: () => Promise<string>;
24
+ manageAccount: () => void;
25
+ requestSignIn: (e?: RequestSignIn) => void;
26
+ signOut: () => void;
27
+ user: UserContext;
28
+ };
29
+
30
+ type UserContext = {
31
+ data: {
32
+ user_id?: string;
33
+ email?: string | null;
34
+ phone?: string | null;
35
+ [key: string]: any;
36
+ };
37
+ set: (data: Record<string, any>) => void;
38
+ setValue: (key: string, value: any) => void;
39
+ isLoading: boolean;
40
+ };
41
+
42
+ type AuthContext = {
43
+ access_token: string | null;
44
+ app_id: string | null;
45
+ is_verified_user?: boolean;
46
+ auth_level?: string | null;
47
+ };
48
+
49
+ export function useRownd(): TRowndContext {
50
+ const { state } = useRowndContext();
51
+
52
+ return {
53
+ access_token: state.auth.access_token,
54
+ auth: state.auth,
55
+ getAccessToken,
56
+ is_authenticated: !!state.auth.access_token,
57
+ is_initializing: !state.auth.app_id,
58
+ manageAccount,
59
+ requestSignIn,
60
+ signOut,
61
+ user: {
62
+ data: state.user.data,
63
+ setValue: setUserDataValue,
64
+ set: setUserData,
65
+ isLoading: state.user.isLoading,
66
+ },
67
+ };
68
+ }
@@ -0,0 +1,56 @@
1
+ import { useRownd as useReactRownd } from '@supertokens/rownd-react';
2
+ import type { TRowndContext } from './rownd';
3
+ import type { RequestSignIn } from '../types';
4
+
5
+ function toWebSignInOptions(opts?: RequestSignIn) {
6
+ if (!opts) {
7
+ return undefined;
8
+ }
9
+
10
+ const method = opts.method === 'guest' ? 'anonymous' : opts.method;
11
+
12
+ return {
13
+ ...opts,
14
+ method,
15
+ post_login_redirect: opts.postSignInRedirect,
16
+ };
17
+ }
18
+
19
+ export function useRownd(): TRowndContext {
20
+ const {
21
+ requestSignIn,
22
+ signOut,
23
+ getAccessToken,
24
+ is_authenticated,
25
+ is_initializing,
26
+ auth,
27
+ access_token,
28
+ user,
29
+ manageAccount,
30
+ setUser,
31
+ setUserValue,
32
+ } = useReactRownd() as any;
33
+
34
+ return {
35
+ access_token,
36
+ auth: {
37
+ access_token,
38
+ app_id: auth.app_id || null,
39
+ is_verified_user: auth.is_verified_user,
40
+ auth_level: auth.auth_level,
41
+ },
42
+ // @ts-ignore
43
+ getAccessToken,
44
+ is_authenticated,
45
+ is_initializing,
46
+ manageAccount,
47
+ requestSignIn: (opts) => requestSignIn(toWebSignInOptions(opts)),
48
+ signOut,
49
+ user: {
50
+ data: user.data,
51
+ setValue: setUserValue,
52
+ set: setUser,
53
+ isLoading: Boolean(user.isLoading ?? user.is_loading),
54
+ },
55
+ };
56
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,7 @@
1
+ import { RowndProvider } from './components/GlobalContext';
2
+ import { useRownd } from './hooks/rownd';
3
+ import RequireSignIn from './components/RequireSignIn';
4
+ import SignedIn from './components/SignedIn';
5
+ import SignedOut from './components/SignedOut';
6
+
7
+ export { RowndProvider, useRownd, RequireSignIn, SignedIn, SignedOut };
@@ -0,0 +1,63 @@
1
+ import type { GlobalState } from '../components/GlobalContext.types';
2
+ import { ActionType, TAction } from '../constants/action';
3
+
4
+ export const initialRowndState: GlobalState = {
5
+ // is_initializing: false,
6
+ user: {
7
+ data: {
8
+ email: null,
9
+ },
10
+ isLoading: false,
11
+ // meta: {}
12
+ },
13
+ auth: {
14
+ access_token: null,
15
+ refresh_token: null,
16
+ app_id: null,
17
+ },
18
+ app: {
19
+ schema: null,
20
+ config: null,
21
+ },
22
+ // is_saving_user_data: false,
23
+ // config,
24
+ };
25
+
26
+ export function rowndReducer(state: GlobalState, action: TAction): GlobalState {
27
+ let newState: GlobalState;
28
+
29
+ switch (action.type) {
30
+ case ActionType.UPDATE_STATE:
31
+ const user = action.payload?.user || {};
32
+ const auth = action.payload?.auth || {};
33
+ const appConfig = action.payload?.appConfig || {};
34
+
35
+ newState = {
36
+ user: {
37
+ data: {
38
+ ...user.data,
39
+ email: user.data?.email,
40
+ },
41
+ isLoading: Boolean(user.isLoading ?? user.is_loading),
42
+ // meta: {}
43
+ },
44
+ auth: {
45
+ access_token: auth.access_token ?? null,
46
+ refresh_token: auth.refresh_token ?? null,
47
+ app_id: appConfig.id || auth.app_id || null,
48
+ is_verified_user: auth.is_verified_user,
49
+ auth_level: auth.auth_level ?? user.auth_level ?? null,
50
+ },
51
+ app: {
52
+ schema: appConfig.schema ?? null,
53
+ config: null,
54
+ },
55
+ // is_saving_user_data: false,
56
+ // config
57
+ };
58
+ return newState;
59
+ default:
60
+ newState = state;
61
+ return newState;
62
+ }
63
+ }
package/src/types.ts ADDED
@@ -0,0 +1,32 @@
1
+ export type SuperTokensConfig = {
2
+ appInfo: {
3
+ appName?: string;
4
+ apiDomain: string;
5
+ apiBasePath?: string;
6
+ };
7
+ };
8
+
9
+ export type RowndProviderConfig = {
10
+ appKey: string;
11
+ supertokens: SuperTokensConfig;
12
+ hubUrlOverride?: string;
13
+ deepLinkScheme?: string;
14
+ };
15
+
16
+ export type RequestSignInMethods =
17
+ | 'default'
18
+ | 'email'
19
+ | 'phone'
20
+ | 'google'
21
+ | 'apple'
22
+ | 'anonymous'
23
+ | 'guest';
24
+
25
+ export type RequestSignInIntent = 'sign_in' | 'sign_up';
26
+
27
+ export type RequestSignIn = {
28
+ method?: RequestSignInMethods;
29
+ postSignInRedirect?: string;
30
+ intent?: RequestSignInIntent;
31
+ prevent_closing?: boolean;
32
+ };
@@ -0,0 +1,9 @@
1
+ import type { RowndProviderConfig } from '../types';
2
+
3
+ export type IConfig = RowndProviderConfig;
4
+
5
+ export interface Customizations {
6
+ sheetBackgroundHexColor?: string;
7
+ sheetCornerBorderRadius?: string;
8
+ loadingAnimation?: string;
9
+ }
@@ -0,0 +1,83 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import type { RequestSignIn } from '../types';
3
+ import type { Customizations, IConfig } from './config';
4
+
5
+ export const LINKING_ERROR =
6
+ `The package '@supertokens/rownd-react-native' doesn't seem to be linked. Make sure: \n\n` +
7
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
8
+ '- You rebuilt the app after installing the package\n' +
9
+ '- You are not using Expo managed workflow\n';
10
+
11
+ export const Rownd = NativeModules.RowndPlugin
12
+ ? NativeModules.RowndPlugin
13
+ : new Proxy(
14
+ {},
15
+ {
16
+ get() {
17
+ throw new Error(LINKING_ERROR);
18
+ },
19
+ }
20
+ );
21
+
22
+ export const IOSRowndEventEmitter =
23
+ Platform.OS !== 'ios'
24
+ ? null
25
+ : NativeModules.RowndPluginEventEmitter
26
+ ? NativeModules.RowndPluginEventEmitter
27
+ : new Proxy(
28
+ {},
29
+ {
30
+ get() {
31
+ throw new Error(LINKING_ERROR);
32
+ },
33
+ }
34
+ );
35
+
36
+ export function configure(config: IConfig): Promise<string> {
37
+ return Rownd.configure(config);
38
+ }
39
+
40
+ export function customizations(customizationConfig: Customizations) {
41
+ return Rownd.customizations(customizationConfig);
42
+ }
43
+
44
+ export function requestSignIn(config?: RequestSignIn) {
45
+ const method = config?.method === 'guest' ? 'anonymous' : config?.method;
46
+
47
+ if (!config) {
48
+ return Rownd.requestSignIn({ method: 'default' });
49
+ }
50
+
51
+ return Rownd.requestSignIn({
52
+ method: method || 'default',
53
+ postSignInRedirect: config?.postSignInRedirect,
54
+ intent: config?.intent,
55
+ });
56
+ }
57
+
58
+ export function signOut() {
59
+ return Rownd.signOut();
60
+ }
61
+
62
+ export function manageAccount() {
63
+ return Rownd.manageAccount();
64
+ }
65
+
66
+ export function getAccessToken(): Promise<string> {
67
+ return Rownd.getAccessToken();
68
+ }
69
+
70
+ export function setUserDataValue(key: string, value: any) {
71
+ return Rownd.setUserDataValue(
72
+ key,
73
+ Platform.OS === 'android' ? { value } : value
74
+ );
75
+ }
76
+
77
+ export function setUserData(data: Record<string, any>) {
78
+ return Rownd.setUserData(data);
79
+ }
80
+
81
+ export function handleSignInLink(url: string) {
82
+ return Rownd.handleSignInLink(url);
83
+ }