@logto/capacitor 4.0.3 → 4.0.5
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/lib/index.js +19 -5
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -42,19 +42,18 @@ class CapacitorLogtoClient extends LogtoBaseClient {
|
|
|
42
42
|
throw new TypeError('The first argument must be a string or a URL.');
|
|
43
43
|
}
|
|
44
44
|
return new Promise((resolve, reject) => {
|
|
45
|
+
// eslint-disable-next-line @silverhand/fp/no-let
|
|
46
|
+
let redirectionHandled = false;
|
|
45
47
|
const run = async () => {
|
|
46
48
|
const [browserHandle, appHandle] = await Promise.all([
|
|
47
|
-
// Handle the case where the user closes the browser during the sign-in.
|
|
48
|
-
Browser.addListener('browserFinished', async () => {
|
|
49
|
-
await Promise.all([browserHandle.remove(), appHandle.remove()]);
|
|
50
|
-
reject(new LogtoClientError('user_cancelled'));
|
|
51
|
-
}),
|
|
52
49
|
// Handle the case where the user completes the sign-in and is redirected
|
|
53
50
|
// back to the app.
|
|
54
51
|
App.addListener('appUrlOpen', async ({ url }) => {
|
|
55
52
|
if (!url.startsWith(redirectUri.toString())) {
|
|
56
53
|
return;
|
|
57
54
|
}
|
|
55
|
+
// eslint-disable-next-line @silverhand/fp/no-mutation
|
|
56
|
+
redirectionHandled = true;
|
|
58
57
|
await Promise.all([
|
|
59
58
|
// One last step of the sign-in flow
|
|
60
59
|
this.handleSignInCallback(url),
|
|
@@ -65,6 +64,21 @@ class CapacitorLogtoClient extends LogtoBaseClient {
|
|
|
65
64
|
]);
|
|
66
65
|
resolve();
|
|
67
66
|
}),
|
|
67
|
+
// Handle the case where the user closes the browser during the sign-in.
|
|
68
|
+
Browser.addListener('browserFinished', async () => {
|
|
69
|
+
// On Android, the browserFinished event will be triggered on deep link redirection,
|
|
70
|
+
// and may arrive before the appUrlOpen event. We need to wait for a short period
|
|
71
|
+
// to ensure the appUrlOpen event is handled first.
|
|
72
|
+
const BROWSER_FINISHED_GRACE_PERIOD_MS = 150;
|
|
73
|
+
await new Promise((resolve) => {
|
|
74
|
+
setTimeout(resolve, BROWSER_FINISHED_GRACE_PERIOD_MS);
|
|
75
|
+
});
|
|
76
|
+
if (redirectionHandled) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
await Promise.all([browserHandle.remove(), appHandle.remove()]);
|
|
80
|
+
reject(new LogtoClientError('user_cancelled'));
|
|
81
|
+
}),
|
|
68
82
|
// Open the in-app browser to start the sign-in flow
|
|
69
83
|
super.signIn(redirectUri, interactionMode),
|
|
70
84
|
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logto/capacitor",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"module": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"directory": "packages/capacitor"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@logto/browser": "^3.0.
|
|
22
|
+
"@logto/browser": "^3.0.12"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@capacitor/app": "^7.0.0",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@capacitor/app": "^7.0.0",
|
|
47
|
-
"@capacitor/browser": "^7.0.0",
|
|
48
|
-
"@capacitor/preferences": "^7.0.0"
|
|
46
|
+
"@capacitor/app": "^7.0.0 || ^8.0.0",
|
|
47
|
+
"@capacitor/browser": "^7.0.0 || ^8.0.0",
|
|
48
|
+
"@capacitor/preferences": "^7.0.0 || ^8.0.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"dev:tsc": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
|