react-native-nitro-auth 0.5.5 → 0.5.6
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 +22 -17
- package/android/proguard-rules.pro +7 -1
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/cpp/PlatformAuth+Android.cpp +260 -67
- package/android/src/main/java/com/auth/AuthAdapter.kt +217 -146
- 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 +173 -60
- package/ios/PlatformAuth+iOS.mm +10 -3
- 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 +9 -7
- 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 +13 -5
- package/lib/commonjs/use-auth.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 +9 -7
- 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 +13 -5
- package/lib/module/use-auth.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.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/logger.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/logger.d.ts.map +1 -1
- package/package.json +2 -4
- 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 +9 -7
- 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 +35 -8
- package/src/utils/logger.ts +1 -0
package/src/service.ts
CHANGED
|
@@ -29,7 +29,8 @@ export const AuthService: Auth = {
|
|
|
29
29
|
|
|
30
30
|
async login(provider: AuthProvider, options?: LoginOptions) {
|
|
31
31
|
try {
|
|
32
|
-
|
|
32
|
+
await nitroAuth.login(provider, options);
|
|
33
|
+
return;
|
|
33
34
|
} catch (e) {
|
|
34
35
|
throw AuthError.from(e);
|
|
35
36
|
}
|
|
@@ -37,7 +38,8 @@ export const AuthService: Auth = {
|
|
|
37
38
|
|
|
38
39
|
async requestScopes(scopes: string[]) {
|
|
39
40
|
try {
|
|
40
|
-
|
|
41
|
+
await nitroAuth.requestScopes(scopes);
|
|
42
|
+
return;
|
|
41
43
|
} catch (e) {
|
|
42
44
|
throw AuthError.from(e);
|
|
43
45
|
}
|
|
@@ -45,7 +47,8 @@ export const AuthService: Auth = {
|
|
|
45
47
|
|
|
46
48
|
async revokeScopes(scopes: string[]) {
|
|
47
49
|
try {
|
|
48
|
-
|
|
50
|
+
await nitroAuth.revokeScopes(scopes);
|
|
51
|
+
return;
|
|
49
52
|
} catch (e) {
|
|
50
53
|
throw AuthError.from(e);
|
|
51
54
|
}
|
|
@@ -73,16 +76,15 @@ export const AuthService: Auth = {
|
|
|
73
76
|
|
|
74
77
|
async silentRestore() {
|
|
75
78
|
try {
|
|
76
|
-
|
|
79
|
+
await nitroAuth.silentRestore();
|
|
80
|
+
return;
|
|
77
81
|
} catch (e) {
|
|
78
82
|
throw AuthError.from(e);
|
|
79
83
|
}
|
|
80
84
|
},
|
|
81
85
|
|
|
82
86
|
onAuthStateChanged(callback: (user: AuthUser | undefined) => void) {
|
|
83
|
-
return nitroAuth.onAuthStateChanged(
|
|
84
|
-
callback(user);
|
|
85
|
-
});
|
|
87
|
+
return nitroAuth.onAuthStateChanged(callback);
|
|
86
88
|
},
|
|
87
89
|
|
|
88
90
|
onTokensRefreshed(callback: (tokens: AuthTokens) => void) {
|
package/src/service.web.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Auth,
|
|
3
|
+
AuthProvider,
|
|
4
|
+
AuthTokens,
|
|
5
|
+
LoginOptions,
|
|
6
|
+
AuthUser,
|
|
7
|
+
} from "./Auth.nitro";
|
|
1
8
|
import { AuthModule } from "./Auth.web";
|
|
9
|
+
import { AuthError } from "./utils/auth-error";
|
|
2
10
|
|
|
3
|
-
export const AuthService = {
|
|
4
|
-
...AuthModule,
|
|
5
|
-
|
|
11
|
+
export const AuthService: Auth = {
|
|
6
12
|
get name() {
|
|
7
13
|
return AuthModule.name;
|
|
8
14
|
},
|
|
@@ -19,16 +25,79 @@ export const AuthService = {
|
|
|
19
25
|
return AuthModule.hasPlayServices;
|
|
20
26
|
},
|
|
21
27
|
|
|
22
|
-
login:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
async login(provider: AuthProvider, options?: LoginOptions) {
|
|
29
|
+
try {
|
|
30
|
+
await AuthModule.login(provider, options);
|
|
31
|
+
return;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
throw AuthError.from(e);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
async requestScopes(scopes: string[]) {
|
|
38
|
+
try {
|
|
39
|
+
await AuthModule.requestScopes(scopes);
|
|
40
|
+
return;
|
|
41
|
+
} catch (e) {
|
|
42
|
+
throw AuthError.from(e);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
async revokeScopes(scopes: string[]) {
|
|
47
|
+
try {
|
|
48
|
+
await AuthModule.revokeScopes(scopes);
|
|
49
|
+
return;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
throw AuthError.from(e);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
async getAccessToken() {
|
|
56
|
+
try {
|
|
57
|
+
return await AuthModule.getAccessToken();
|
|
58
|
+
} catch (e) {
|
|
59
|
+
throw AuthError.from(e);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
async refreshToken() {
|
|
64
|
+
try {
|
|
65
|
+
return await AuthModule.refreshToken();
|
|
66
|
+
} catch (e) {
|
|
67
|
+
throw AuthError.from(e);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
logout() {
|
|
72
|
+
AuthModule.logout();
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
async silentRestore() {
|
|
76
|
+
try {
|
|
77
|
+
await AuthModule.silentRestore();
|
|
78
|
+
return;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
throw AuthError.from(e);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
onAuthStateChanged(callback: (user: AuthUser | undefined) => void) {
|
|
85
|
+
return AuthModule.onAuthStateChanged(callback);
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
onTokensRefreshed(callback: (tokens: AuthTokens) => void) {
|
|
89
|
+
return AuthModule.onTokensRefreshed(callback);
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
setLoggingEnabled(enabled: boolean) {
|
|
93
|
+
AuthModule.setLoggingEnabled(enabled);
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
dispose() {
|
|
97
|
+
AuthModule.dispose();
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
equals(other: Parameters<Auth["equals"]>[0]): boolean {
|
|
101
|
+
return AuthModule.equals(other);
|
|
102
|
+
},
|
|
34
103
|
};
|
package/src/ui/social-button.tsx
CHANGED
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
View,
|
|
8
8
|
ActivityIndicator,
|
|
9
9
|
} from "react-native";
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
10
|
+
import { AuthService } from "../service";
|
|
11
|
+
import { logger } from "../utils/logger";
|
|
12
|
+
import type { AuthProvider, AuthUser } from "../Auth.nitro";
|
|
12
13
|
|
|
13
14
|
export type SocialButtonVariant = "primary" | "outline" | "white" | "black";
|
|
14
15
|
|
|
@@ -56,8 +57,7 @@ const getTextColor = (variant: SocialButtonVariant): string =>
|
|
|
56
57
|
variant === "white" || variant === "outline" ? "#000000" : "#FFFFFF";
|
|
57
58
|
|
|
58
59
|
async function performLogin(provider: AuthProvider): Promise<void> {
|
|
59
|
-
|
|
60
|
-
await auth.login(provider);
|
|
60
|
+
await AuthService.login(provider);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export const SocialButton = ({
|
|
@@ -83,12 +83,16 @@ export const SocialButton = ({
|
|
|
83
83
|
setLoading(true);
|
|
84
84
|
try {
|
|
85
85
|
await performLogin(provider);
|
|
86
|
-
const user =
|
|
86
|
+
const user = AuthService.currentUser;
|
|
87
87
|
if (user) {
|
|
88
88
|
onSuccess?.(user);
|
|
89
89
|
}
|
|
90
90
|
} catch (error) {
|
|
91
|
-
onError
|
|
91
|
+
if (onError) {
|
|
92
|
+
onError(error);
|
|
93
|
+
} else if (__DEV__) {
|
|
94
|
+
logger.error("SocialButton unhandled error:", error);
|
|
95
|
+
}
|
|
92
96
|
} finally {
|
|
93
97
|
setLoading(false);
|
|
94
98
|
}
|
|
@@ -126,19 +130,21 @@ export const SocialButton = ({
|
|
|
126
130
|
<>
|
|
127
131
|
{provider === "google" && variant !== "primary" && (
|
|
128
132
|
<View style={styles.iconPlaceholder}>
|
|
129
|
-
<Text style={
|
|
133
|
+
<Text style={styles.iconText}>G</Text>
|
|
130
134
|
</View>
|
|
131
135
|
)}
|
|
132
136
|
{provider === "apple" && variant !== "primary" && (
|
|
133
137
|
<View style={styles.iconPlaceholder}>
|
|
134
|
-
<Text
|
|
138
|
+
<Text
|
|
139
|
+
style={[styles.iconText, { color: getTextColor(variant) }]}
|
|
140
|
+
>
|
|
135
141
|
|
|
136
142
|
</Text>
|
|
137
143
|
</View>
|
|
138
144
|
)}
|
|
139
145
|
{provider === "microsoft" && variant !== "primary" && (
|
|
140
146
|
<View style={styles.iconPlaceholder}>
|
|
141
|
-
<Text style={
|
|
147
|
+
<Text style={styles.microsoftIconText}>⊞</Text>
|
|
142
148
|
</View>
|
|
143
149
|
)}
|
|
144
150
|
<Text
|
|
@@ -179,4 +185,10 @@ const styles = StyleSheet.create({
|
|
|
179
185
|
fontSize: 16,
|
|
180
186
|
fontWeight: "600",
|
|
181
187
|
},
|
|
188
|
+
iconText: {
|
|
189
|
+
fontSize: 18,
|
|
190
|
+
},
|
|
191
|
+
microsoftIconText: {
|
|
192
|
+
fontSize: 16,
|
|
193
|
+
},
|
|
182
194
|
});
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ActivityIndicator,
|
|
9
9
|
} from "react-native";
|
|
10
10
|
import { AuthModule } from "../Auth.web";
|
|
11
|
+
import { logger } from "../utils/logger";
|
|
11
12
|
import type { AuthProvider, AuthUser } from "../Auth.nitro";
|
|
12
13
|
|
|
13
14
|
export type SocialButtonVariant = "primary" | "outline" | "white" | "black";
|
|
@@ -87,7 +88,11 @@ export const SocialButton = ({
|
|
|
87
88
|
onSuccess?.(user);
|
|
88
89
|
}
|
|
89
90
|
} catch (error) {
|
|
90
|
-
onError
|
|
91
|
+
if (onError) {
|
|
92
|
+
onError(error);
|
|
93
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
94
|
+
logger.error("SocialButton unhandled error:", error);
|
|
95
|
+
}
|
|
91
96
|
} finally {
|
|
92
97
|
setLoading(false);
|
|
93
98
|
}
|
|
@@ -125,19 +130,21 @@ export const SocialButton = ({
|
|
|
125
130
|
<>
|
|
126
131
|
{provider === "google" && variant !== "primary" && (
|
|
127
132
|
<View style={styles.iconPlaceholder}>
|
|
128
|
-
<Text style={
|
|
133
|
+
<Text style={styles.iconText}>G</Text>
|
|
129
134
|
</View>
|
|
130
135
|
)}
|
|
131
136
|
{provider === "apple" && variant !== "primary" && (
|
|
132
137
|
<View style={styles.iconPlaceholder}>
|
|
133
|
-
<Text
|
|
138
|
+
<Text
|
|
139
|
+
style={[styles.iconText, { color: getTextColor(variant) }]}
|
|
140
|
+
>
|
|
134
141
|
|
|
135
142
|
</Text>
|
|
136
143
|
</View>
|
|
137
144
|
)}
|
|
138
145
|
{provider === "microsoft" && variant !== "primary" && (
|
|
139
146
|
<View style={styles.iconPlaceholder}>
|
|
140
|
-
<Text style={
|
|
147
|
+
<Text style={styles.microsoftIconText}>⊞</Text>
|
|
141
148
|
</View>
|
|
142
149
|
)}
|
|
143
150
|
<Text
|
|
@@ -178,4 +185,10 @@ const styles = StyleSheet.create({
|
|
|
178
185
|
fontSize: 16,
|
|
179
186
|
fontWeight: "600",
|
|
180
187
|
},
|
|
188
|
+
iconText: {
|
|
189
|
+
fontSize: 18,
|
|
190
|
+
},
|
|
191
|
+
microsoftIconText: {
|
|
192
|
+
fontSize: 16,
|
|
193
|
+
},
|
|
181
194
|
});
|
package/src/use-auth.ts
CHANGED
|
@@ -17,8 +17,10 @@ type AuthState = {
|
|
|
17
17
|
|
|
18
18
|
const areScopesEqual = (left: string[], right: string[]): boolean => {
|
|
19
19
|
if (left.length !== right.length) return false;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const sortedLeft = [...left].sort();
|
|
21
|
+
const sortedRight = [...right].sort();
|
|
22
|
+
for (let i = 0; i < sortedLeft.length; i += 1) {
|
|
23
|
+
if (sortedLeft[i] !== sortedRight[i]) return false;
|
|
22
24
|
}
|
|
23
25
|
return true;
|
|
24
26
|
};
|
|
@@ -55,7 +57,12 @@ export function useAuth(): UseAuthReturn {
|
|
|
55
57
|
) {
|
|
56
58
|
return prev;
|
|
57
59
|
}
|
|
58
|
-
return {
|
|
60
|
+
return {
|
|
61
|
+
user: nextUser,
|
|
62
|
+
scopes: nextScopes,
|
|
63
|
+
loading: nextLoading,
|
|
64
|
+
error: nextError,
|
|
65
|
+
};
|
|
59
66
|
});
|
|
60
67
|
},
|
|
61
68
|
[],
|
|
@@ -139,7 +146,7 @@ export function useAuth(): UseAuthReturn {
|
|
|
139
146
|
}, [syncStateFromService]);
|
|
140
147
|
|
|
141
148
|
useEffect(() => {
|
|
142
|
-
const
|
|
149
|
+
const unsubscribeAuth = AuthService.onAuthStateChanged((currentUser) => {
|
|
143
150
|
const nextScopes = AuthService.grantedScopes;
|
|
144
151
|
setState((prev) => {
|
|
145
152
|
if (
|
|
@@ -149,11 +156,22 @@ export function useAuth(): UseAuthReturn {
|
|
|
149
156
|
) {
|
|
150
157
|
return prev;
|
|
151
158
|
}
|
|
152
|
-
return {
|
|
159
|
+
return {
|
|
160
|
+
...prev,
|
|
161
|
+
user: currentUser,
|
|
162
|
+
scopes: nextScopes,
|
|
163
|
+
loading: false,
|
|
164
|
+
};
|
|
153
165
|
});
|
|
154
166
|
});
|
|
155
|
-
|
|
156
|
-
|
|
167
|
+
const unsubscribeTokens = AuthService.onTokensRefreshed?.(() => {
|
|
168
|
+
syncStateFromService(false, undefined);
|
|
169
|
+
});
|
|
170
|
+
return () => {
|
|
171
|
+
unsubscribeAuth();
|
|
172
|
+
unsubscribeTokens?.();
|
|
173
|
+
};
|
|
174
|
+
}, [syncStateFromService]);
|
|
157
175
|
|
|
158
176
|
return useMemo(
|
|
159
177
|
() => ({
|
|
@@ -167,6 +185,15 @@ export function useAuth(): UseAuthReturn {
|
|
|
167
185
|
refreshToken,
|
|
168
186
|
silentRestore,
|
|
169
187
|
}),
|
|
170
|
-
[
|
|
188
|
+
[
|
|
189
|
+
state,
|
|
190
|
+
login,
|
|
191
|
+
logout,
|
|
192
|
+
requestScopes,
|
|
193
|
+
revokeScopes,
|
|
194
|
+
getAccessToken,
|
|
195
|
+
refreshToken,
|
|
196
|
+
silentRestore,
|
|
197
|
+
],
|
|
171
198
|
);
|
|
172
199
|
}
|
package/src/utils/logger.ts
CHANGED