react-native-nitro-auth 0.5.9 → 0.5.11
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/CHANGELOG.md +36 -0
- package/README.md +5 -0
- package/ios/AuthAdapter.swift +28 -9
- package/lib/commonjs/create-auth-service.js +33 -14
- package/lib/commonjs/create-auth-service.js.map +1 -1
- package/lib/module/create-auth-service.js +33 -14
- package/lib/module/create-auth-service.js.map +1 -1
- package/lib/typescript/commonjs/create-auth-service.d.ts.map +1 -1
- package/lib/typescript/module/create-auth-service.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/create-auth-service.ts +34 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.11 - 2026-05-05
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Updated the Expo example to the Expo SDK 55 recommended `expo@~55.0.23` patch and Android API 36 target.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Wrapped synchronous native service failures in `AuthError` so public service errors keep a consistent code contract.
|
|
12
|
+
|
|
13
|
+
### Verified
|
|
14
|
+
|
|
15
|
+
- `bun install --frozen-lockfile`
|
|
16
|
+
- `bunx expo install --check --cwd apps/example`
|
|
17
|
+
- `bunx expo-doctor@latest apps/example`
|
|
18
|
+
- `bun run check:ci`
|
|
19
|
+
- `bun run --cwd packages/react-native-nitro-auth test:coverage -- --runInBand`
|
|
20
|
+
- `bun run --cwd packages/react-native-nitro-auth test:cpp:coverage`
|
|
21
|
+
- `bun run example:prebuild`
|
|
22
|
+
- `bun run publish-package:dry-run`
|
|
23
|
+
|
|
24
|
+
## 0.5.10 - 2026-04-27
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
|
|
28
|
+
- Fixed iOS Microsoft sign-in so `ASWebAuthenticationSession` is retained until callback or cancellation and duplicate sessions fail with `operation_in_progress`.
|
|
29
|
+
- Fixed the example app header so it displays the current package version.
|
|
30
|
+
|
|
31
|
+
### Verified
|
|
32
|
+
|
|
33
|
+
- `bun run check:ci`
|
|
34
|
+
- `bunx expo install --check --cwd apps/example`
|
|
35
|
+
- `bunx expo-doctor@latest apps/example`
|
|
36
|
+
- `bun run example:prebuild`
|
|
37
|
+
- `bun run publish-package:dry-run`
|
|
38
|
+
|
|
3
39
|
## 0.5.9 - 2026-04-24
|
|
4
40
|
|
|
5
41
|
### Added
|
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# react-native-nitro-auth
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
3
8
|
Fast React Native authentication for Google Sign-In, Apple Sign-In, and Microsoft Entra ID, built on Nitro Modules and JSI.
|
|
4
9
|
|
|
5
10
|
`react-native-nitro-auth` gives Expo and React Native apps one typed API for native social login, web OAuth, token refresh, incremental scopes, and auth state listeners without owning your app's long-term token storage.
|
package/ios/AuthAdapter.swift
CHANGED
|
@@ -10,6 +10,7 @@ public class AuthAdapter: NSObject {
|
|
|
10
10
|
private static var inMemoryMicrosoftRefreshToken: String?
|
|
11
11
|
private static var inMemoryMicrosoftScopes: [String] = defaultMicrosoftScopes
|
|
12
12
|
private static var inMemoryGoogleServerAuthCode: String?
|
|
13
|
+
private static var activeMicrosoftWebAuthSession: ASWebAuthenticationSession?
|
|
13
14
|
private static let tokenStoreLock = NSLock()
|
|
14
15
|
|
|
15
16
|
@objc
|
|
@@ -135,22 +136,32 @@ public class AuthAdapter: NSObject {
|
|
|
135
136
|
let callbackScheme = "msauth.\(bundleId)"
|
|
136
137
|
|
|
137
138
|
DispatchQueue.main.async {
|
|
139
|
+
guard self.activeMicrosoftWebAuthSession == nil else {
|
|
140
|
+
completion(nil, "operation_in_progress")
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let completeAndClearSession = { (data: NSDictionary?, error: String?) in
|
|
145
|
+
self.activeMicrosoftWebAuthSession = nil
|
|
146
|
+
completion(data, error)
|
|
147
|
+
}
|
|
148
|
+
|
|
138
149
|
let session = ASWebAuthenticationSession(url: authUrl, callbackURLScheme: callbackScheme) { callbackURL, error in
|
|
139
150
|
if let error = error {
|
|
140
151
|
let nsError = error as NSError
|
|
141
152
|
if nsError.code == ASWebAuthenticationSessionError.canceledLogin.rawValue {
|
|
142
|
-
|
|
153
|
+
completeAndClearSession(nil, "cancelled")
|
|
143
154
|
} else if nsError.domain.lowercased().contains("network") || nsError.code == NSURLErrorNotConnectedToInternet {
|
|
144
|
-
|
|
155
|
+
completeAndClearSession(nil, "network_error")
|
|
145
156
|
} else {
|
|
146
|
-
|
|
157
|
+
completeAndClearSession(nil, "unknown")
|
|
147
158
|
}
|
|
148
159
|
return
|
|
149
160
|
}
|
|
150
161
|
|
|
151
162
|
guard let callbackURL = callbackURL,
|
|
152
163
|
let components = URLComponents(url: callbackURL, resolvingAgainstBaseURL: false) else {
|
|
153
|
-
|
|
164
|
+
completeAndClearSession(nil, "unknown")
|
|
154
165
|
return
|
|
155
166
|
}
|
|
156
167
|
|
|
@@ -163,20 +174,21 @@ public class AuthAdapter: NSObject {
|
|
|
163
174
|
// OAuth error codes are already structured (e.g. "access_denied").
|
|
164
175
|
// Map well-known ones; fall back to "unknown".
|
|
165
176
|
let mapped = mapOAuthError(errorCode)
|
|
166
|
-
|
|
177
|
+
completeAndClearSession(nil, mapped)
|
|
167
178
|
return
|
|
168
179
|
}
|
|
169
180
|
|
|
170
181
|
guard let returnedState = params["state"], returnedState == state else {
|
|
171
|
-
|
|
182
|
+
completeAndClearSession(nil, "invalid_state")
|
|
172
183
|
return
|
|
173
184
|
}
|
|
174
185
|
|
|
175
186
|
guard let code = params["code"] else {
|
|
176
|
-
|
|
187
|
+
completeAndClearSession(nil, "unknown")
|
|
177
188
|
return
|
|
178
189
|
}
|
|
179
190
|
|
|
191
|
+
self.activeMicrosoftWebAuthSession = nil
|
|
180
192
|
exchangeCodeForTokens(
|
|
181
193
|
code: code,
|
|
182
194
|
codeVerifier: codeVerifier,
|
|
@@ -191,14 +203,17 @@ public class AuthAdapter: NSObject {
|
|
|
191
203
|
}
|
|
192
204
|
|
|
193
205
|
guard let window = activeWindow() else {
|
|
194
|
-
|
|
206
|
+
completeAndClearSession(nil, "no_window")
|
|
195
207
|
return
|
|
196
208
|
}
|
|
197
209
|
let contextProvider = WebAuthContextProvider(anchor: window)
|
|
198
210
|
session.presentationContextProvider = contextProvider
|
|
199
211
|
objc_setAssociatedObject(session, &contextProviderHandle, contextProvider, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
|
200
212
|
session.prefersEphemeralWebBrowserSession = false
|
|
201
|
-
session
|
|
213
|
+
self.activeMicrosoftWebAuthSession = session
|
|
214
|
+
if !session.start() {
|
|
215
|
+
completeAndClearSession(nil, "unknown")
|
|
216
|
+
}
|
|
202
217
|
}
|
|
203
218
|
}
|
|
204
219
|
|
|
@@ -685,6 +700,10 @@ public class AuthAdapter: NSObject {
|
|
|
685
700
|
@objc
|
|
686
701
|
public static func logout() {
|
|
687
702
|
GIDSignIn.sharedInstance.signOut()
|
|
703
|
+
DispatchQueue.main.async {
|
|
704
|
+
self.activeMicrosoftWebAuthSession?.cancel()
|
|
705
|
+
self.activeMicrosoftWebAuthSession = nil
|
|
706
|
+
}
|
|
688
707
|
tokenStoreLock.lock()
|
|
689
708
|
inMemoryMicrosoftRefreshToken = nil
|
|
690
709
|
inMemoryMicrosoftScopes = defaultMicrosoftScopes
|
|
@@ -12,20 +12,29 @@ async function wrapAuthOperation(operation) {
|
|
|
12
12
|
throw _authError.AuthError.from(e);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
function wrapSyncAuthOperation(operation) {
|
|
16
|
+
try {
|
|
17
|
+
return operation();
|
|
18
|
+
} catch (e) {
|
|
19
|
+
throw _authError.AuthError.from(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
15
22
|
function createAuthService(getAuth) {
|
|
16
23
|
return {
|
|
17
24
|
get name() {
|
|
18
|
-
return getAuth().name;
|
|
25
|
+
return wrapSyncAuthOperation(() => getAuth().name);
|
|
19
26
|
},
|
|
20
27
|
get currentUser() {
|
|
21
|
-
return getAuth().currentUser;
|
|
28
|
+
return wrapSyncAuthOperation(() => getAuth().currentUser);
|
|
22
29
|
},
|
|
23
30
|
get grantedScopes() {
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
return wrapSyncAuthOperation(() => {
|
|
32
|
+
const scopes = getAuth().grantedScopes;
|
|
33
|
+
return Array.isArray(scopes) ? scopes : [];
|
|
34
|
+
});
|
|
26
35
|
},
|
|
27
36
|
get hasPlayServices() {
|
|
28
|
-
return getAuth().hasPlayServices;
|
|
37
|
+
return wrapSyncAuthOperation(() => getAuth().hasPlayServices);
|
|
29
38
|
},
|
|
30
39
|
login(provider, options) {
|
|
31
40
|
return wrapAuthOperation(() => getAuth().login(provider, options));
|
|
@@ -43,28 +52,38 @@ function createAuthService(getAuth) {
|
|
|
43
52
|
return wrapAuthOperation(() => getAuth().refreshToken());
|
|
44
53
|
},
|
|
45
54
|
logout() {
|
|
46
|
-
|
|
55
|
+
wrapSyncAuthOperation(() => {
|
|
56
|
+
getAuth().logout();
|
|
57
|
+
});
|
|
47
58
|
},
|
|
48
59
|
silentRestore() {
|
|
49
60
|
return wrapAuthOperation(() => getAuth().silentRestore());
|
|
50
61
|
},
|
|
51
62
|
onAuthStateChanged(callback) {
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
return wrapSyncAuthOperation(() => {
|
|
64
|
+
const auth = getAuth();
|
|
65
|
+
return auth.onAuthStateChanged?.(callback) ?? (() => {});
|
|
66
|
+
});
|
|
54
67
|
},
|
|
55
68
|
onTokensRefreshed(callback) {
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
return wrapSyncAuthOperation(() => {
|
|
70
|
+
const auth = getAuth();
|
|
71
|
+
return auth.onTokensRefreshed?.(callback) ?? (() => {});
|
|
72
|
+
});
|
|
58
73
|
},
|
|
59
74
|
setLoggingEnabled(enabled) {
|
|
60
|
-
|
|
61
|
-
|
|
75
|
+
wrapSyncAuthOperation(() => {
|
|
76
|
+
const auth = getAuth();
|
|
77
|
+
auth.setLoggingEnabled?.(enabled);
|
|
78
|
+
});
|
|
62
79
|
},
|
|
63
80
|
dispose() {
|
|
64
|
-
|
|
81
|
+
wrapSyncAuthOperation(() => {
|
|
82
|
+
getAuth().dispose();
|
|
83
|
+
});
|
|
65
84
|
},
|
|
66
85
|
equals(other) {
|
|
67
|
-
return getAuth().equals(other);
|
|
86
|
+
return wrapSyncAuthOperation(() => getAuth().equals(other));
|
|
68
87
|
}
|
|
69
88
|
};
|
|
70
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_authError","require","wrapAuthOperation","operation","e","AuthError","from","createAuthService","getAuth","name","currentUser","grantedScopes","scopes","Array","isArray","hasPlayServices","login","provider","options","requestScopes","revokeScopes","getAccessToken","refreshToken","logout","silentRestore","onAuthStateChanged","callback","auth","onTokensRefreshed","setLoggingEnabled","enabled","dispose","equals","other"],"sourceRoot":"../../src","sources":["create-auth-service.ts"],"mappings":";;;;;;AAOA,IAAAA,UAAA,GAAAC,OAAA;AAWA,eAAeC,iBAAiBA,CAAIC,SAA2B,EAAc;EAC3E,IAAI;IACF,OAAO,MAAMA,SAAS,CAAC,CAAC;EAC1B,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,MAAMC,oBAAS,CAACC,IAAI,CAACF,CAAC,CAAC;EACzB;AACF;
|
|
1
|
+
{"version":3,"names":["_authError","require","wrapAuthOperation","operation","e","AuthError","from","wrapSyncAuthOperation","createAuthService","getAuth","name","currentUser","grantedScopes","scopes","Array","isArray","hasPlayServices","login","provider","options","requestScopes","revokeScopes","getAccessToken","refreshToken","logout","silentRestore","onAuthStateChanged","callback","auth","onTokensRefreshed","setLoggingEnabled","enabled","dispose","equals","other"],"sour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,CAAC,CAAC;IACJ,CAAC;IAEDG,iBAAiBA,CAACC,OAAgB,EAAE;MAClCxB,qBAAqB,CAAC,MAAM;QAC1B,MAAMqB,IAAI,GAAGnB,OAAO,CAAC,CAAkC;QACvDmB,IAAI,CAACE,iBAAiB,GAAGC,OAAO,CAAC;MACnC,CAAC,CAAC;IACJ,CAAC;IAEDC,OAAOA,CAAA,EAAG;MACRzB,qBAAqB,CAAC,MAAM;QAC1BE,OAAO,CAAC,CAAC,CAACuB,OAAO,CAAC,CAAC;MACrB,CAAC,CAAC;IACJ,CAAC;IAEDC,MAAMA,CAACC,KAAoC,EAAW;MACpD,OAAO3B,qBAAqB,CAAC,MAAME,OAAO,CAAC,CAAC,CAACwB,MAAM,CAACC,KAAK,CAAC,CAAC;IAC7D;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -8,20 +8,29 @@ async function wrapAuthOperation(operation) {
|
|
|
8
8
|
throw AuthError.from(e);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
function wrapSyncAuthOperation(operation) {
|
|
12
|
+
try {
|
|
13
|
+
return operation();
|
|
14
|
+
} catch (e) {
|
|
15
|
+
throw AuthError.from(e);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
11
18
|
export function createAuthService(getAuth) {
|
|
12
19
|
return {
|
|
13
20
|
get name() {
|
|
14
|
-
return getAuth().name;
|
|
21
|
+
return wrapSyncAuthOperation(() => getAuth().name);
|
|
15
22
|
},
|
|
16
23
|
get currentUser() {
|
|
17
|
-
return getAuth().currentUser;
|
|
24
|
+
return wrapSyncAuthOperation(() => getAuth().currentUser);
|
|
18
25
|
},
|
|
19
26
|
get grantedScopes() {
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
return wrapSyncAuthOperation(() => {
|
|
28
|
+
const scopes = getAuth().grantedScopes;
|
|
29
|
+
return Array.isArray(scopes) ? scopes : [];
|
|
30
|
+
});
|
|
22
31
|
},
|
|
23
32
|
get hasPlayServices() {
|
|
24
|
-
return getAuth().hasPlayServices;
|
|
33
|
+
return wrapSyncAuthOperation(() => getAuth().hasPlayServices);
|
|
25
34
|
},
|
|
26
35
|
login(provider, options) {
|
|
27
36
|
return wrapAuthOperation(() => getAuth().login(provider, options));
|
|
@@ -39,28 +48,38 @@ export function createAuthService(getAuth) {
|
|
|
39
48
|
return wrapAuthOperation(() => getAuth().refreshToken());
|
|
40
49
|
},
|
|
41
50
|
logout() {
|
|
42
|
-
|
|
51
|
+
wrapSyncAuthOperation(() => {
|
|
52
|
+
getAuth().logout();
|
|
53
|
+
});
|
|
43
54
|
},
|
|
44
55
|
silentRestore() {
|
|
45
56
|
return wrapAuthOperation(() => getAuth().silentRestore());
|
|
46
57
|
},
|
|
47
58
|
onAuthStateChanged(callback) {
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
return wrapSyncAuthOperation(() => {
|
|
60
|
+
const auth = getAuth();
|
|
61
|
+
return auth.onAuthStateChanged?.(callback) ?? (() => {});
|
|
62
|
+
});
|
|
50
63
|
},
|
|
51
64
|
onTokensRefreshed(callback) {
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
return wrapSyncAuthOperation(() => {
|
|
66
|
+
const auth = getAuth();
|
|
67
|
+
return auth.onTokensRefreshed?.(callback) ?? (() => {});
|
|
68
|
+
});
|
|
54
69
|
},
|
|
55
70
|
setLoggingEnabled(enabled) {
|
|
56
|
-
|
|
57
|
-
|
|
71
|
+
wrapSyncAuthOperation(() => {
|
|
72
|
+
const auth = getAuth();
|
|
73
|
+
auth.setLoggingEnabled?.(enabled);
|
|
74
|
+
});
|
|
58
75
|
},
|
|
59
76
|
dispose() {
|
|
60
|
-
|
|
77
|
+
wrapSyncAuthOperation(() => {
|
|
78
|
+
getAuth().dispose();
|
|
79
|
+
});
|
|
61
80
|
},
|
|
62
81
|
equals(other) {
|
|
63
|
-
return getAuth().equals(other);
|
|
82
|
+
return wrapSyncAuthOperation(() => getAuth().equals(other));
|
|
64
83
|
}
|
|
65
84
|
};
|
|
66
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AuthError","wrapAuthOperation","operation","e","from","createAuthService","getAuth","name","currentUser","grantedScopes","scopes","Array","isArray","hasPlayServices","login","provider","options","requestScopes","revokeScopes","getAccessToken","refreshToken","logout","silentRestore","onAuthStateChanged","callback","auth","onTokensRefreshed","setLoggingEnabled","enabled","dispose","equals","other"],"sourceRoot":"../../src","sources":["create-auth-service.ts"],"mappings":";;AAOA,SAASA,SAAS,QAAQ,uBAAoB;AAW9C,eAAeC,iBAAiBA,CAAIC,SAA2B,EAAc;EAC3E,IAAI;IACF,OAAO,MAAMA,SAAS,CAAC,CAAC;EAC1B,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,MAAMH,SAAS,CAACI,IAAI,CAACD,CAAC,CAAC;EACzB;AACF;AAEA,OAAO,
|
|
1
|
+
{"version":3,"names":["AuthError","wrapAuthOperation","operation","e","from","wrapSyncAuthOperation","createAuthService","getAuth","name","currentUser","grantedScopes","scopes","Array","isArray","hasPlayServices","login","provider","options","requestScopes","revokeScopes","getAccessToken","refreshToken","logout","silentRestore","onAuthStateChanged","callback","auth","onTokensRefreshed","setLoggingEnabled","enabled","dispose","equals","other"],"sourceRoot":"../../src","sources":["create-auth-service.ts"],"mappings":";;AAOA,SAASA,SAAS,QAAQ,uBAAoB;AAW9C,eAAeC,iBAAiBA,CAAIC,SAA2B,EAAc;EAC3E,IAAI;IACF,OAAO,MAAMA,SAAS,CAAC,CAAC;EAC1B,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,MAAMH,SAAS,CAACI,IAAI,CAACD,CAAC,CAAC;EACzB;AACF;AAEA,SAASE,qBAAqBA,CAAIH,SAAkB,EAAK;EACvD,IAAI;IACF,OAAOA,SAAS,CAAC,CAAC;EACpB,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV,MAAMH,SAAS,CAACI,IAAI,CAACD,CAAC,CAAC;EACzB;AACF;AAEA,OAAO,SAASG,iBAAiBA,CAACC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;IAC7D;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-auth-service.d.ts","sourceRoot":"","sources":["../../../src/create-auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAGtB,KAAK,UAAU,GAAG,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"create-auth-service.d.ts","sourceRoot":"","sources":["../../../src/create-auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAGtB,KAAK,UAAU,GAAG,MAAM,IAAI,CAAC;AAyB7B,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAkF3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-auth-service.d.ts","sourceRoot":"","sources":["../../../src/create-auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAGtB,KAAK,UAAU,GAAG,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"create-auth-service.d.ts","sourceRoot":"","sources":["../../../src/create-auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAGtB,KAAK,UAAU,GAAG,MAAM,IAAI,CAAC;AAyB7B,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,CAkF3D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-auth",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
4
4
|
"description": "High-performance authentication library for React Native with Google Sign-In, Apple Sign-In, and Microsoft Sign-In support, powered by Nitro Modules (JSI)",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -24,23 +24,33 @@ async function wrapAuthOperation<T>(operation: () => Promise<T>): Promise<T> {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
function wrapSyncAuthOperation<T>(operation: () => T): T {
|
|
28
|
+
try {
|
|
29
|
+
return operation();
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw AuthError.from(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
export function createAuthService(getAuth: AuthSource): Auth {
|
|
28
36
|
return {
|
|
29
37
|
get name() {
|
|
30
|
-
return getAuth().name;
|
|
38
|
+
return wrapSyncAuthOperation(() => getAuth().name);
|
|
31
39
|
},
|
|
32
40
|
|
|
33
41
|
get currentUser() {
|
|
34
|
-
return getAuth().currentUser;
|
|
42
|
+
return wrapSyncAuthOperation(() => getAuth().currentUser);
|
|
35
43
|
},
|
|
36
44
|
|
|
37
45
|
get grantedScopes() {
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
return wrapSyncAuthOperation(() => {
|
|
47
|
+
const scopes = getAuth().grantedScopes;
|
|
48
|
+
return Array.isArray(scopes) ? scopes : [];
|
|
49
|
+
});
|
|
40
50
|
},
|
|
41
51
|
|
|
42
52
|
get hasPlayServices() {
|
|
43
|
-
return getAuth().hasPlayServices;
|
|
53
|
+
return wrapSyncAuthOperation(() => getAuth().hasPlayServices);
|
|
44
54
|
},
|
|
45
55
|
|
|
46
56
|
login(provider: AuthProvider, options?: LoginOptions) {
|
|
@@ -64,7 +74,9 @@ export function createAuthService(getAuth: AuthSource): Auth {
|
|
|
64
74
|
},
|
|
65
75
|
|
|
66
76
|
logout() {
|
|
67
|
-
|
|
77
|
+
wrapSyncAuthOperation(() => {
|
|
78
|
+
getAuth().logout();
|
|
79
|
+
});
|
|
68
80
|
},
|
|
69
81
|
|
|
70
82
|
silentRestore() {
|
|
@@ -72,26 +84,34 @@ export function createAuthService(getAuth: AuthSource): Auth {
|
|
|
72
84
|
},
|
|
73
85
|
|
|
74
86
|
onAuthStateChanged(callback: (user: AuthUser | undefined) => void) {
|
|
75
|
-
|
|
76
|
-
|
|
87
|
+
return wrapSyncAuthOperation(() => {
|
|
88
|
+
const auth = getAuth() as AuthWithOptionalNativeMembers;
|
|
89
|
+
return auth.onAuthStateChanged?.(callback) ?? (() => {});
|
|
90
|
+
});
|
|
77
91
|
},
|
|
78
92
|
|
|
79
93
|
onTokensRefreshed(callback: (tokens: AuthTokens) => void) {
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
return wrapSyncAuthOperation(() => {
|
|
95
|
+
const auth = getAuth() as AuthWithOptionalNativeMembers;
|
|
96
|
+
return auth.onTokensRefreshed?.(callback) ?? (() => {});
|
|
97
|
+
});
|
|
82
98
|
},
|
|
83
99
|
|
|
84
100
|
setLoggingEnabled(enabled: boolean) {
|
|
85
|
-
|
|
86
|
-
|
|
101
|
+
wrapSyncAuthOperation(() => {
|
|
102
|
+
const auth = getAuth() as AuthWithOptionalNativeMembers;
|
|
103
|
+
auth.setLoggingEnabled?.(enabled);
|
|
104
|
+
});
|
|
87
105
|
},
|
|
88
106
|
|
|
89
107
|
dispose() {
|
|
90
|
-
|
|
108
|
+
wrapSyncAuthOperation(() => {
|
|
109
|
+
getAuth().dispose();
|
|
110
|
+
});
|
|
91
111
|
},
|
|
92
112
|
|
|
93
113
|
equals(other: Parameters<Auth["equals"]>[0]): boolean {
|
|
94
|
-
return getAuth().equals(other);
|
|
114
|
+
return wrapSyncAuthOperation(() => getAuth().equals(other));
|
|
95
115
|
},
|
|
96
116
|
};
|
|
97
117
|
}
|