react-native-nitro-auth 0.5.1 → 0.5.4
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.
- package/README.md +362 -190
- package/android/build.gradle +2 -5
- package/android/src/main/cpp/PlatformAuth+Android.cpp +84 -18
- package/android/src/main/java/com/auth/AuthAdapter.kt +82 -182
- package/android/src/main/java/com/auth/NitroAuthPackage.kt +1 -1
- package/app.plugin.js +2 -9
- package/cpp/AuthCache.cpp +0 -134
- package/cpp/AuthCache.hpp +0 -7
- package/cpp/HybridAuth.cpp +57 -63
- package/cpp/HybridAuth.hpp +3 -4
- package/ios/AuthAdapter.swift +23 -25
- package/lib/commonjs/Auth.web.js +523 -201
- package/lib/commonjs/Auth.web.js.map +1 -1
- package/lib/commonjs/index.js +0 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +0 -12
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/js-storage-adapter.js +2 -0
- package/lib/commonjs/js-storage-adapter.js.map +1 -0
- package/lib/commonjs/service.js +9 -86
- package/lib/commonjs/service.js.map +1 -1
- package/lib/commonjs/service.web.js +1 -5
- package/lib/commonjs/service.web.js.map +1 -1
- package/lib/commonjs/ui/social-button.js +44 -29
- package/lib/commonjs/ui/social-button.js.map +1 -1
- package/lib/commonjs/ui/social-button.web.js +44 -29
- package/lib/commonjs/ui/social-button.web.js.map +1 -1
- package/lib/commonjs/use-auth.js +56 -42
- package/lib/commonjs/use-auth.js.map +1 -1
- package/lib/commonjs/utils/logger.js +12 -4
- package/lib/commonjs/utils/logger.js.map +1 -1
- package/lib/module/Auth.web.js +523 -201
- package/lib/module/Auth.web.js.map +1 -1
- package/lib/module/index.js +0 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +0 -1
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/js-storage-adapter.js +2 -0
- package/lib/module/js-storage-adapter.js.map +1 -0
- package/lib/module/service.js +9 -86
- package/lib/module/service.js.map +1 -1
- package/lib/module/service.web.js +1 -5
- package/lib/module/service.web.js.map +1 -1
- package/lib/module/ui/social-button.js +44 -29
- package/lib/module/ui/social-button.js.map +1 -1
- package/lib/module/ui/social-button.web.js +44 -29
- package/lib/module/ui/social-button.web.js.map +1 -1
- package/lib/module/use-auth.js +56 -42
- package/lib/module/use-auth.js.map +1 -1
- package/lib/module/utils/logger.js +12 -4
- package/lib/module/utils/logger.js.map +1 -1
- package/lib/typescript/commonjs/Auth.nitro.d.ts +3 -3
- package/lib/typescript/commonjs/Auth.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/Auth.web.d.ts +25 -6
- package/lib/typescript/commonjs/Auth.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -2
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +0 -1
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/js-storage-adapter.d.ts +6 -0
- package/lib/typescript/commonjs/js-storage-adapter.d.ts.map +1 -0
- package/lib/typescript/commonjs/service.d.ts +1 -8
- package/lib/typescript/commonjs/service.d.ts.map +1 -1
- package/lib/typescript/commonjs/service.web.d.ts +1 -8
- package/lib/typescript/commonjs/service.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/social-button.d.ts +6 -6
- package/lib/typescript/commonjs/ui/social-button.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/social-button.web.d.ts +6 -6
- package/lib/typescript/commonjs/ui/social-button.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/use-auth.d.ts +4 -4
- package/lib/typescript/commonjs/use-auth.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/logger.d.ts +4 -4
- package/lib/typescript/commonjs/utils/logger.d.ts.map +1 -1
- package/lib/typescript/module/Auth.nitro.d.ts +3 -3
- package/lib/typescript/module/Auth.nitro.d.ts.map +1 -1
- package/lib/typescript/module/Auth.web.d.ts +25 -6
- package/lib/typescript/module/Auth.web.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -2
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +0 -1
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/js-storage-adapter.d.ts +6 -0
- package/lib/typescript/module/js-storage-adapter.d.ts.map +1 -0
- package/lib/typescript/module/service.d.ts +1 -8
- package/lib/typescript/module/service.d.ts.map +1 -1
- package/lib/typescript/module/service.web.d.ts +1 -8
- package/lib/typescript/module/service.web.d.ts.map +1 -1
- package/lib/typescript/module/ui/social-button.d.ts +6 -6
- package/lib/typescript/module/ui/social-button.d.ts.map +1 -1
- package/lib/typescript/module/ui/social-button.web.d.ts +6 -6
- package/lib/typescript/module/ui/social-button.web.d.ts.map +1 -1
- package/lib/typescript/module/use-auth.d.ts +4 -4
- package/lib/typescript/module/use-auth.d.ts.map +1 -1
- package/lib/typescript/module/utils/logger.d.ts +4 -4
- package/lib/typescript/module/utils/logger.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroAuth+autolinking.cmake +0 -1
- package/nitrogen/generated/shared/c++/AuthTokens.hpp +5 -1
- package/nitrogen/generated/shared/c++/AuthUser.hpp +5 -1
- package/nitrogen/generated/shared/c++/HybridAuthSpec.cpp +0 -1
- package/nitrogen/generated/shared/c++/HybridAuthSpec.hpp +0 -5
- package/package.json +11 -8
- package/react-native-nitro-auth.podspec +1 -1
- package/src/Auth.nitro.ts +4 -3
- package/src/Auth.web.ts +700 -246
- package/src/global.d.ts +0 -1
- package/src/index.ts +1 -2
- package/src/index.web.ts +0 -1
- package/src/js-storage-adapter.ts +5 -0
- package/src/service.ts +13 -106
- package/src/service.web.ts +0 -7
- package/src/ui/social-button.tsx +66 -43
- package/src/ui/social-button.web.tsx +67 -44
- package/src/use-auth.ts +116 -72
- package/src/utils/logger.ts +12 -4
- package/ios/KeychainStore.swift +0 -43
- package/lib/commonjs/AuthStorage.nitro.js +0 -6
- package/lib/commonjs/AuthStorage.nitro.js.map +0 -1
- package/lib/module/AuthStorage.nitro.js +0 -4
- package/lib/module/AuthStorage.nitro.js.map +0 -1
- package/lib/typescript/commonjs/AuthStorage.nitro.d.ts +0 -26
- package/lib/typescript/commonjs/AuthStorage.nitro.d.ts.map +0 -1
- package/lib/typescript/module/AuthStorage.nitro.d.ts +0 -26
- package/lib/typescript/module/AuthStorage.nitro.d.ts.map +0 -1
- package/nitrogen/generated/shared/c++/HybridAuthStorageAdapterSpec.cpp +0 -23
- package/nitrogen/generated/shared/c++/HybridAuthStorageAdapterSpec.hpp +0 -65
- package/src/AuthStorage.nitro.ts +0 -26
package/src/use-auth.ts
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
import { useState, useEffect, useCallback, useMemo } from "react";
|
|
2
|
-
import { AuthService } from "./service";
|
|
3
2
|
import type {
|
|
4
3
|
AuthUser,
|
|
5
4
|
AuthProvider,
|
|
6
5
|
LoginOptions,
|
|
7
6
|
AuthTokens,
|
|
8
7
|
} from "./Auth.nitro";
|
|
8
|
+
import { AuthService } from "./service";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
type AuthState = {
|
|
11
11
|
user: AuthUser | undefined;
|
|
12
12
|
scopes: string[];
|
|
13
13
|
loading: boolean;
|
|
14
14
|
error: Error | undefined;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const areScopesEqual = (left: string[], right: string[]): boolean => {
|
|
18
|
+
if (left.length !== right.length) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
23
|
+
if (left[index] !== right[index]) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class AuthHookError extends Error {
|
|
32
|
+
public readonly underlyingError?: string;
|
|
33
|
+
|
|
34
|
+
constructor(message: string, underlyingError?: string) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "AuthHookError";
|
|
37
|
+
this.underlyingError = underlyingError;
|
|
38
|
+
}
|
|
15
39
|
}
|
|
16
40
|
|
|
17
|
-
export
|
|
41
|
+
export type UseAuthReturn = AuthState & {
|
|
18
42
|
hasPlayServices: boolean;
|
|
19
43
|
login: (provider: AuthProvider, options?: LoginOptions) => Promise<void>;
|
|
20
44
|
logout: () => void;
|
|
@@ -23,7 +47,7 @@ export interface UseAuthReturn extends AuthState {
|
|
|
23
47
|
getAccessToken: () => Promise<string | undefined>;
|
|
24
48
|
refreshToken: () => Promise<AuthTokens>;
|
|
25
49
|
silentRestore: () => Promise<void>;
|
|
26
|
-
}
|
|
50
|
+
};
|
|
27
51
|
|
|
28
52
|
export function useAuth(): UseAuthReturn {
|
|
29
53
|
const [state, setState] = useState<AuthState>({
|
|
@@ -33,17 +57,37 @@ export function useAuth(): UseAuthReturn {
|
|
|
33
57
|
error: undefined,
|
|
34
58
|
});
|
|
35
59
|
|
|
60
|
+
const syncStateFromService = useCallback(
|
|
61
|
+
(nextLoading: boolean, nextError: Error | undefined) => {
|
|
62
|
+
const nextUser = AuthService.currentUser;
|
|
63
|
+
const nextScopes = AuthService.grantedScopes;
|
|
64
|
+
setState((prev) => {
|
|
65
|
+
if (
|
|
66
|
+
prev.loading === nextLoading &&
|
|
67
|
+
prev.error === nextError &&
|
|
68
|
+
prev.user === nextUser &&
|
|
69
|
+
areScopesEqual(prev.scopes, nextScopes)
|
|
70
|
+
) {
|
|
71
|
+
return prev;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
user: nextUser,
|
|
76
|
+
scopes: nextScopes,
|
|
77
|
+
loading: nextLoading,
|
|
78
|
+
error: nextError,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
[],
|
|
83
|
+
);
|
|
84
|
+
|
|
36
85
|
const login = useCallback(
|
|
37
86
|
async (provider: AuthProvider, options?: LoginOptions) => {
|
|
38
87
|
setState((prev) => ({ ...prev, loading: true, error: undefined }));
|
|
39
88
|
try {
|
|
40
89
|
await AuthService.login(provider, options);
|
|
41
|
-
|
|
42
|
-
user: AuthService.currentUser,
|
|
43
|
-
scopes: AuthService.grantedScopes,
|
|
44
|
-
loading: false,
|
|
45
|
-
error: undefined,
|
|
46
|
-
});
|
|
90
|
+
syncStateFromService(false, undefined);
|
|
47
91
|
} catch (e) {
|
|
48
92
|
const error = e instanceof Error ? e : new Error(String(e));
|
|
49
93
|
setState((prev) => ({
|
|
@@ -54,7 +98,7 @@ export function useAuth(): UseAuthReturn {
|
|
|
54
98
|
throw error;
|
|
55
99
|
}
|
|
56
100
|
},
|
|
57
|
-
[],
|
|
101
|
+
[syncStateFromService],
|
|
58
102
|
);
|
|
59
103
|
|
|
60
104
|
const logout = useCallback(() => {
|
|
@@ -67,47 +111,43 @@ export function useAuth(): UseAuthReturn {
|
|
|
67
111
|
});
|
|
68
112
|
}, []);
|
|
69
113
|
|
|
70
|
-
const requestScopes = useCallback(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
}, []);
|
|
114
|
+
const requestScopes = useCallback(
|
|
115
|
+
async (newScopes: string[]) => {
|
|
116
|
+
setState((prev) => ({ ...prev, loading: true, error: undefined }));
|
|
117
|
+
try {
|
|
118
|
+
await AuthService.requestScopes(newScopes);
|
|
119
|
+
syncStateFromService(false, undefined);
|
|
120
|
+
} catch (e) {
|
|
121
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
122
|
+
setState((prev) => ({
|
|
123
|
+
...prev,
|
|
124
|
+
loading: false,
|
|
125
|
+
error,
|
|
126
|
+
}));
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
[syncStateFromService],
|
|
131
|
+
);
|
|
90
132
|
|
|
91
|
-
const revokeScopes = useCallback(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
}, []);
|
|
133
|
+
const revokeScopes = useCallback(
|
|
134
|
+
async (scopesToRevoke: string[]) => {
|
|
135
|
+
setState((prev) => ({ ...prev, loading: true, error: undefined }));
|
|
136
|
+
try {
|
|
137
|
+
await AuthService.revokeScopes(scopesToRevoke);
|
|
138
|
+
syncStateFromService(false, undefined);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
141
|
+
setState((prev) => ({
|
|
142
|
+
...prev,
|
|
143
|
+
loading: false,
|
|
144
|
+
error,
|
|
145
|
+
}));
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
[syncStateFromService],
|
|
150
|
+
);
|
|
111
151
|
|
|
112
152
|
const getAccessToken = useCallback(() => AuthService.getAccessToken(), []);
|
|
113
153
|
|
|
@@ -115,17 +155,14 @@ export function useAuth(): UseAuthReturn {
|
|
|
115
155
|
setState((prev) => ({ ...prev, loading: true, error: undefined }));
|
|
116
156
|
try {
|
|
117
157
|
const tokens = await AuthService.refreshToken();
|
|
118
|
-
|
|
119
|
-
user: AuthService.currentUser,
|
|
120
|
-
scopes: AuthService.grantedScopes,
|
|
121
|
-
loading: false,
|
|
122
|
-
error: undefined,
|
|
123
|
-
});
|
|
158
|
+
syncStateFromService(false, undefined);
|
|
124
159
|
return tokens;
|
|
125
160
|
} catch (e) {
|
|
126
161
|
const msg = e instanceof Error ? e.message : String(e);
|
|
127
|
-
const authError = new
|
|
128
|
-
|
|
162
|
+
const authError = new AuthHookError(
|
|
163
|
+
msg,
|
|
164
|
+
AuthService.currentUser?.underlyingError,
|
|
165
|
+
);
|
|
129
166
|
setState((prev) => ({
|
|
130
167
|
...prev,
|
|
131
168
|
loading: false,
|
|
@@ -133,18 +170,13 @@ export function useAuth(): UseAuthReturn {
|
|
|
133
170
|
}));
|
|
134
171
|
throw authError;
|
|
135
172
|
}
|
|
136
|
-
}, []);
|
|
173
|
+
}, [syncStateFromService]);
|
|
137
174
|
|
|
138
175
|
const silentRestore = useCallback(async () => {
|
|
139
176
|
setState((prev) => ({ ...prev, loading: true, error: undefined }));
|
|
140
177
|
try {
|
|
141
178
|
await AuthService.silentRestore();
|
|
142
|
-
|
|
143
|
-
user: AuthService.currentUser,
|
|
144
|
-
scopes: AuthService.grantedScopes,
|
|
145
|
-
loading: false,
|
|
146
|
-
error: undefined,
|
|
147
|
-
});
|
|
179
|
+
syncStateFromService(false, undefined);
|
|
148
180
|
} catch (e) {
|
|
149
181
|
const error = e instanceof Error ? e : new Error(String(e));
|
|
150
182
|
setState((prev) => ({
|
|
@@ -154,15 +186,27 @@ export function useAuth(): UseAuthReturn {
|
|
|
154
186
|
}));
|
|
155
187
|
throw error;
|
|
156
188
|
}
|
|
157
|
-
}, []);
|
|
189
|
+
}, [syncStateFromService]);
|
|
158
190
|
|
|
159
191
|
useEffect(() => {
|
|
160
192
|
const unsubscribe = AuthService.onAuthStateChanged((currentUser) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
193
|
+
const nextScopes = AuthService.grantedScopes;
|
|
194
|
+
setState((prev) => {
|
|
195
|
+
if (
|
|
196
|
+
prev.user === currentUser &&
|
|
197
|
+
areScopesEqual(prev.scopes, nextScopes) &&
|
|
198
|
+
prev.loading === false
|
|
199
|
+
) {
|
|
200
|
+
return prev;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
...prev,
|
|
205
|
+
user: currentUser,
|
|
206
|
+
scopes: nextScopes,
|
|
207
|
+
loading: false,
|
|
208
|
+
};
|
|
209
|
+
});
|
|
166
210
|
});
|
|
167
211
|
return unsubscribe;
|
|
168
212
|
}, []);
|
package/src/utils/logger.ts
CHANGED
|
@@ -4,8 +4,16 @@ export const logger = {
|
|
|
4
4
|
setEnabled(value: boolean): void {
|
|
5
5
|
enabled = value;
|
|
6
6
|
},
|
|
7
|
-
log: (...args: unknown[]) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
log: (...args: unknown[]) => {
|
|
8
|
+
if (enabled) console.log("[NitroAuth]", ...args);
|
|
9
|
+
},
|
|
10
|
+
warn: (...args: unknown[]) => {
|
|
11
|
+
if (enabled) console.warn("[NitroAuth]", ...args);
|
|
12
|
+
},
|
|
13
|
+
error: (...args: unknown[]) => {
|
|
14
|
+
if (enabled) console.error("[NitroAuth]", ...args);
|
|
15
|
+
},
|
|
16
|
+
debug: (...args: unknown[]) => {
|
|
17
|
+
if (enabled) console.debug("[NitroAuth]", ...args);
|
|
18
|
+
},
|
|
11
19
|
};
|
package/ios/KeychainStore.swift
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Security
|
|
3
|
-
|
|
4
|
-
enum KeychainStore {
|
|
5
|
-
private static let service = "react-native-nitro-auth"
|
|
6
|
-
|
|
7
|
-
static func set(_ value: String, for key: String) {
|
|
8
|
-
guard let data = value.data(using: .utf8) else { return }
|
|
9
|
-
let baseQuery: [String: Any] = [
|
|
10
|
-
kSecClass as String: kSecClassGenericPassword,
|
|
11
|
-
kSecAttrService as String: service,
|
|
12
|
-
kSecAttrAccount as String: key
|
|
13
|
-
]
|
|
14
|
-
SecItemDelete(baseQuery as CFDictionary)
|
|
15
|
-
var attributes = baseQuery
|
|
16
|
-
attributes[kSecValueData as String] = data
|
|
17
|
-
attributes[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
|
|
18
|
-
SecItemAdd(attributes as CFDictionary, nil)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static func get(_ key: String) -> String? {
|
|
22
|
-
let query: [String: Any] = [
|
|
23
|
-
kSecClass as String: kSecClassGenericPassword,
|
|
24
|
-
kSecAttrService as String: service,
|
|
25
|
-
kSecAttrAccount as String: key,
|
|
26
|
-
kSecReturnData as String: kCFBooleanTrue as Any,
|
|
27
|
-
kSecMatchLimit as String: kSecMatchLimitOne
|
|
28
|
-
]
|
|
29
|
-
var item: CFTypeRef?
|
|
30
|
-
let status = SecItemCopyMatching(query as CFDictionary, &item)
|
|
31
|
-
guard status == errSecSuccess, let data = item as? Data else { return nil }
|
|
32
|
-
return String(data: data, encoding: .utf8)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
static func remove(_ key: String) {
|
|
36
|
-
let query: [String: Any] = [
|
|
37
|
-
kSecClass as String: kSecClassGenericPassword,
|
|
38
|
-
kSecAttrService as String: service,
|
|
39
|
-
kSecAttrAccount as String: key
|
|
40
|
-
]
|
|
41
|
-
SecItemDelete(query as CFDictionary)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["AuthStorage.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["AuthStorage.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { HybridObject } from "react-native-nitro-modules";
|
|
2
|
-
/**
|
|
3
|
-
* Custom storage adapter for persisting auth state.
|
|
4
|
-
*
|
|
5
|
-
* On native platforms, this must be a native HybridObject (Swift/Kotlin).
|
|
6
|
-
* For JS-based storage (AsyncStorage, MMKV), use the JS wrapper approach
|
|
7
|
-
* documented in the README.
|
|
8
|
-
*/
|
|
9
|
-
export interface AuthStorageAdapter extends HybridObject<{
|
|
10
|
-
ios: "c++";
|
|
11
|
-
android: "c++";
|
|
12
|
-
}> {
|
|
13
|
-
/**
|
|
14
|
-
* Called to save a value to the custom storage.
|
|
15
|
-
*/
|
|
16
|
-
save(key: string, value: string): void;
|
|
17
|
-
/**
|
|
18
|
-
* Called to load a value from the custom storage.
|
|
19
|
-
*/
|
|
20
|
-
load(key: string): string | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Called to remove a value from the custom storage.
|
|
23
|
-
*/
|
|
24
|
-
remove(key: string): void;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=AuthStorage.nitro.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthStorage.nitro.d.ts","sourceRoot":"","sources":["../../../src/AuthStorage.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY,CAAC;IACvD,GAAG,EAAE,KAAK,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;IACA;;OAEG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC;;OAEG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { HybridObject } from "react-native-nitro-modules";
|
|
2
|
-
/**
|
|
3
|
-
* Custom storage adapter for persisting auth state.
|
|
4
|
-
*
|
|
5
|
-
* On native platforms, this must be a native HybridObject (Swift/Kotlin).
|
|
6
|
-
* For JS-based storage (AsyncStorage, MMKV), use the JS wrapper approach
|
|
7
|
-
* documented in the README.
|
|
8
|
-
*/
|
|
9
|
-
export interface AuthStorageAdapter extends HybridObject<{
|
|
10
|
-
ios: "c++";
|
|
11
|
-
android: "c++";
|
|
12
|
-
}> {
|
|
13
|
-
/**
|
|
14
|
-
* Called to save a value to the custom storage.
|
|
15
|
-
*/
|
|
16
|
-
save(key: string, value: string): void;
|
|
17
|
-
/**
|
|
18
|
-
* Called to load a value from the custom storage.
|
|
19
|
-
*/
|
|
20
|
-
load(key: string): string | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Called to remove a value from the custom storage.
|
|
23
|
-
*/
|
|
24
|
-
remove(key: string): void;
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=AuthStorage.nitro.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AuthStorage.nitro.d.ts","sourceRoot":"","sources":["../../../src/AuthStorage.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY,CAAC;IACvD,GAAG,EAAE,KAAK,CAAC;IACX,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;IACA;;OAEG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC;;OAEG;IACH,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
///
|
|
2
|
-
/// HybridAuthStorageAdapterSpec.cpp
|
|
3
|
-
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
-
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
-
///
|
|
7
|
-
|
|
8
|
-
#include "HybridAuthStorageAdapterSpec.hpp"
|
|
9
|
-
|
|
10
|
-
namespace margelo::nitro::NitroAuth {
|
|
11
|
-
|
|
12
|
-
void HybridAuthStorageAdapterSpec::loadHybridMethods() {
|
|
13
|
-
// load base methods/properties
|
|
14
|
-
HybridObject::loadHybridMethods();
|
|
15
|
-
// load custom methods/properties
|
|
16
|
-
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
-
prototype.registerHybridMethod("save", &HybridAuthStorageAdapterSpec::save);
|
|
18
|
-
prototype.registerHybridMethod("load", &HybridAuthStorageAdapterSpec::load);
|
|
19
|
-
prototype.registerHybridMethod("remove", &HybridAuthStorageAdapterSpec::remove);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
} // namespace margelo::nitro::NitroAuth
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
///
|
|
2
|
-
/// HybridAuthStorageAdapterSpec.hpp
|
|
3
|
-
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
-
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
-
///
|
|
7
|
-
|
|
8
|
-
#pragma once
|
|
9
|
-
|
|
10
|
-
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
-
#include <NitroModules/HybridObject.hpp>
|
|
12
|
-
#else
|
|
13
|
-
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
-
#endif
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
#include <string>
|
|
19
|
-
#include <optional>
|
|
20
|
-
|
|
21
|
-
namespace margelo::nitro::NitroAuth {
|
|
22
|
-
|
|
23
|
-
using namespace margelo::nitro;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* An abstract base class for `AuthStorageAdapter`
|
|
27
|
-
* Inherit this class to create instances of `HybridAuthStorageAdapterSpec` in C++.
|
|
28
|
-
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
29
|
-
* @example
|
|
30
|
-
* ```cpp
|
|
31
|
-
* class HybridAuthStorageAdapter: public HybridAuthStorageAdapterSpec {
|
|
32
|
-
* public:
|
|
33
|
-
* HybridAuthStorageAdapter(...): HybridObject(TAG) { ... }
|
|
34
|
-
* // ...
|
|
35
|
-
* };
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
class HybridAuthStorageAdapterSpec: public virtual HybridObject {
|
|
39
|
-
public:
|
|
40
|
-
// Constructor
|
|
41
|
-
explicit HybridAuthStorageAdapterSpec(): HybridObject(TAG) { }
|
|
42
|
-
|
|
43
|
-
// Destructor
|
|
44
|
-
~HybridAuthStorageAdapterSpec() override = default;
|
|
45
|
-
|
|
46
|
-
public:
|
|
47
|
-
// Properties
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
public:
|
|
51
|
-
// Methods
|
|
52
|
-
virtual void save(const std::string& key, const std::string& value) = 0;
|
|
53
|
-
virtual std::optional<std::string> load(const std::string& key) = 0;
|
|
54
|
-
virtual void remove(const std::string& key) = 0;
|
|
55
|
-
|
|
56
|
-
protected:
|
|
57
|
-
// Hybrid Setup
|
|
58
|
-
void loadHybridMethods() override;
|
|
59
|
-
|
|
60
|
-
protected:
|
|
61
|
-
// Tag for logging
|
|
62
|
-
static constexpr auto TAG = "AuthStorageAdapter";
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
} // namespace margelo::nitro::NitroAuth
|
package/src/AuthStorage.nitro.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { HybridObject } from "react-native-nitro-modules";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Custom storage adapter for persisting auth state.
|
|
5
|
-
*
|
|
6
|
-
* On native platforms, this must be a native HybridObject (Swift/Kotlin).
|
|
7
|
-
* For JS-based storage (AsyncStorage, MMKV), use the JS wrapper approach
|
|
8
|
-
* documented in the README.
|
|
9
|
-
*/
|
|
10
|
-
export interface AuthStorageAdapter extends HybridObject<{
|
|
11
|
-
ios: "c++";
|
|
12
|
-
android: "c++";
|
|
13
|
-
}> {
|
|
14
|
-
/**
|
|
15
|
-
* Called to save a value to the custom storage.
|
|
16
|
-
*/
|
|
17
|
-
save(key: string, value: string): void;
|
|
18
|
-
/**
|
|
19
|
-
* Called to load a value from the custom storage.
|
|
20
|
-
*/
|
|
21
|
-
load(key: string): string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Called to remove a value from the custom storage.
|
|
24
|
-
*/
|
|
25
|
-
remove(key: string): void;
|
|
26
|
-
}
|