react-native-nitro-auth 0.5.5 → 0.5.7
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 +30 -19
- package/android/proguard-rules.pro +7 -1
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/cpp/PlatformAuth+Android.cpp +261 -68
- package/android/src/main/java/com/auth/AuthAdapter.kt +250 -157
- package/android/src/main/java/com/auth/GoogleSignInActivity.kt +9 -5
- package/cpp/HybridAuth.cpp +79 -64
- package/cpp/HybridAuth.hpp +9 -7
- package/cpp/JSONSerializer.hpp +3 -0
- package/ios/AuthAdapter.swift +208 -66
- package/ios/PlatformAuth+iOS.mm +30 -4
- package/lib/commonjs/Auth.web.js +50 -10
- package/lib/commonjs/Auth.web.js.map +1 -1
- package/lib/commonjs/index.web.js +30 -12
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/service.js +25 -19
- package/lib/commonjs/service.js.map +1 -1
- package/lib/commonjs/service.web.js +65 -13
- package/lib/commonjs/service.web.js.map +1 -1
- package/lib/commonjs/ui/social-button.js +19 -14
- package/lib/commonjs/ui/social-button.js.map +1 -1
- package/lib/commonjs/ui/social-button.web.js +16 -10
- package/lib/commonjs/ui/social-button.web.js.map +1 -1
- package/lib/commonjs/use-auth.js +34 -10
- package/lib/commonjs/use-auth.js.map +1 -1
- package/lib/commonjs/utils/auth-error.js +1 -1
- package/lib/commonjs/utils/auth-error.js.map +1 -1
- package/lib/commonjs/utils/logger.js +1 -0
- package/lib/commonjs/utils/logger.js.map +1 -1
- package/lib/module/Auth.web.js +50 -10
- package/lib/module/Auth.web.js.map +1 -1
- package/lib/module/global.d.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +2 -1
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/service.js +25 -19
- package/lib/module/service.js.map +1 -1
- package/lib/module/service.web.js +65 -13
- package/lib/module/service.web.js.map +1 -1
- package/lib/module/ui/social-button.js +19 -14
- package/lib/module/ui/social-button.js.map +1 -1
- package/lib/module/ui/social-button.web.js +16 -10
- package/lib/module/ui/social-button.web.js.map +1 -1
- package/lib/module/use-auth.js +34 -10
- package/lib/module/use-auth.js.map +1 -1
- package/lib/module/utils/auth-error.js +1 -1
- package/lib/module/utils/auth-error.js.map +1 -1
- package/lib/module/utils/logger.js +1 -0
- package/lib/module/utils/logger.js.map +1 -1
- package/lib/typescript/commonjs/Auth.nitro.d.ts +2 -2
- package/lib/typescript/commonjs/Auth.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/Auth.web.d.ts +5 -1
- package/lib/typescript/commonjs/Auth.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -1
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +2 -1
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/service.d.ts.map +1 -1
- package/lib/typescript/commonjs/service.web.d.ts +2 -18
- package/lib/typescript/commonjs/service.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/social-button.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/social-button.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/use-auth.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/auth-error.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/logger.d.ts.map +1 -1
- package/lib/typescript/module/Auth.nitro.d.ts +2 -2
- package/lib/typescript/module/Auth.nitro.d.ts.map +1 -1
- package/lib/typescript/module/Auth.web.d.ts +5 -1
- package/lib/typescript/module/Auth.web.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -1
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +2 -1
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/service.d.ts.map +1 -1
- package/lib/typescript/module/service.web.d.ts +2 -18
- package/lib/typescript/module/service.web.d.ts.map +1 -1
- package/lib/typescript/module/ui/social-button.d.ts.map +1 -1
- package/lib/typescript/module/ui/social-button.web.d.ts.map +1 -1
- package/lib/typescript/module/use-auth.d.ts.map +1 -1
- package/lib/typescript/module/utils/auth-error.d.ts.map +1 -1
- package/lib/typescript/module/utils/logger.d.ts.map +1 -1
- package/nitro.json +4 -1
- package/nitrogen/generated/ios/NitroAuth+autolinking.rb +2 -0
- package/package.json +3 -4
- package/src/Auth.nitro.ts +3 -1
- package/src/Auth.web.ts +77 -11
- package/src/global.d.ts +0 -11
- package/src/index.ts +5 -1
- package/src/index.web.ts +6 -1
- package/src/service.ts +26 -19
- package/src/service.web.ts +84 -15
- package/src/ui/social-button.tsx +21 -9
- package/src/ui/social-button.web.tsx +17 -4
- package/src/use-auth.ts +65 -9
- package/src/utils/auth-error.ts +2 -0
- package/src/utils/logger.ts +1 -0
package/src/use-auth.ts
CHANGED
|
@@ -8,6 +8,8 @@ import type {
|
|
|
8
8
|
import { AuthService } from "./service";
|
|
9
9
|
import { AuthError } from "./utils/auth-error";
|
|
10
10
|
|
|
11
|
+
const EMPTY_SCOPES: string[] = [];
|
|
12
|
+
|
|
11
13
|
type AuthState = {
|
|
12
14
|
user: AuthUser | undefined;
|
|
13
15
|
scopes: string[];
|
|
@@ -16,11 +18,25 @@ type AuthState = {
|
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
const areScopesEqual = (left: string[], right: string[]): boolean => {
|
|
21
|
+
if (left === right) return true;
|
|
19
22
|
if (left.length !== right.length) return false;
|
|
23
|
+
|
|
24
|
+
let matchesInOrder = true;
|
|
20
25
|
for (let i = 0; i < left.length; i += 1) {
|
|
21
|
-
if (left[i] !== right[i])
|
|
26
|
+
if (left[i] !== right[i]) {
|
|
27
|
+
matchesInOrder = false;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (matchesInOrder) return true;
|
|
32
|
+
|
|
33
|
+
const remaining = new Set(left);
|
|
34
|
+
for (const scope of right) {
|
|
35
|
+
if (!remaining.delete(scope)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
22
38
|
}
|
|
23
|
-
return
|
|
39
|
+
return remaining.size === 0;
|
|
24
40
|
};
|
|
25
41
|
|
|
26
42
|
export type UseAuthReturn = AuthState & {
|
|
@@ -55,7 +71,12 @@ export function useAuth(): UseAuthReturn {
|
|
|
55
71
|
) {
|
|
56
72
|
return prev;
|
|
57
73
|
}
|
|
58
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
user: nextUser,
|
|
76
|
+
scopes: nextScopes,
|
|
77
|
+
loading: nextLoading,
|
|
78
|
+
error: nextError,
|
|
79
|
+
};
|
|
59
80
|
});
|
|
60
81
|
},
|
|
61
82
|
[],
|
|
@@ -78,7 +99,22 @@ export function useAuth(): UseAuthReturn {
|
|
|
78
99
|
|
|
79
100
|
const logout = useCallback(() => {
|
|
80
101
|
AuthService.logout();
|
|
81
|
-
setState(
|
|
102
|
+
setState((prev) => {
|
|
103
|
+
if (
|
|
104
|
+
prev.user === undefined &&
|
|
105
|
+
prev.scopes.length === 0 &&
|
|
106
|
+
prev.loading === false &&
|
|
107
|
+
prev.error === undefined
|
|
108
|
+
) {
|
|
109
|
+
return prev;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
user: undefined,
|
|
113
|
+
scopes: EMPTY_SCOPES,
|
|
114
|
+
loading: false,
|
|
115
|
+
error: undefined,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
82
118
|
}, []);
|
|
83
119
|
|
|
84
120
|
const requestScopes = useCallback(
|
|
@@ -139,7 +175,7 @@ export function useAuth(): UseAuthReturn {
|
|
|
139
175
|
}, [syncStateFromService]);
|
|
140
176
|
|
|
141
177
|
useEffect(() => {
|
|
142
|
-
const
|
|
178
|
+
const unsubscribeAuth = AuthService.onAuthStateChanged((currentUser) => {
|
|
143
179
|
const nextScopes = AuthService.grantedScopes;
|
|
144
180
|
setState((prev) => {
|
|
145
181
|
if (
|
|
@@ -149,11 +185,22 @@ export function useAuth(): UseAuthReturn {
|
|
|
149
185
|
) {
|
|
150
186
|
return prev;
|
|
151
187
|
}
|
|
152
|
-
return {
|
|
188
|
+
return {
|
|
189
|
+
...prev,
|
|
190
|
+
user: currentUser,
|
|
191
|
+
scopes: nextScopes,
|
|
192
|
+
loading: false,
|
|
193
|
+
};
|
|
153
194
|
});
|
|
154
195
|
});
|
|
155
|
-
|
|
156
|
-
|
|
196
|
+
const unsubscribeTokens = AuthService.onTokensRefreshed?.(() => {
|
|
197
|
+
syncStateFromService(false, undefined);
|
|
198
|
+
});
|
|
199
|
+
return () => {
|
|
200
|
+
unsubscribeAuth();
|
|
201
|
+
unsubscribeTokens?.();
|
|
202
|
+
};
|
|
203
|
+
}, [syncStateFromService]);
|
|
157
204
|
|
|
158
205
|
return useMemo(
|
|
159
206
|
() => ({
|
|
@@ -167,6 +214,15 @@ export function useAuth(): UseAuthReturn {
|
|
|
167
214
|
refreshToken,
|
|
168
215
|
silentRestore,
|
|
169
216
|
}),
|
|
170
|
-
[
|
|
217
|
+
[
|
|
218
|
+
state,
|
|
219
|
+
login,
|
|
220
|
+
logout,
|
|
221
|
+
requestScopes,
|
|
222
|
+
revokeScopes,
|
|
223
|
+
getAccessToken,
|
|
224
|
+
refreshToken,
|
|
225
|
+
silentRestore,
|
|
226
|
+
],
|
|
171
227
|
);
|
|
172
228
|
}
|
package/src/utils/auth-error.ts
CHANGED
package/src/utils/logger.ts
CHANGED