Skip to content

Commit 1e652b9

Browse files
authored
Merge pull request #1236 from dfinity/lm-change-ii-integration-example-safari-popup-blocked
Fix issue with Safari blocking popup in II integration example
2 parents 53b20db + 95f105a commit 1e652b9

File tree

1 file changed

+12
-3
lines changed
  • motoko/internet_identity_integration/src/greet_frontend/src

1 file changed

+12
-3
lines changed

motoko/internet_identity_integration/src/greet_frontend/src/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import {HttpAgent} from "@dfinity/agent";
44

55
let actor = greet_backend;
66

7+
// create an auth client on page load.
8+
// Safari might block the popup if the app performs other async actions before opening the popup.
9+
// This is why we create the auth client here, and not in the loginButton click handler
10+
let authClient = undefined;
11+
AuthClient.create().then((client) => {
12+
authClient = client;
13+
});
14+
715
const greetButton = document.getElementById("greet");
816
greetButton.onclick = async (e) => {
917
e.preventDefault();
@@ -24,9 +32,10 @@ const loginButton = document.getElementById("login");
2432
loginButton.onclick = async (e) => {
2533
e.preventDefault();
2634

27-
// create an auth client
28-
let authClient = await AuthClient.create();
29-
35+
if (authClient === undefined) {
36+
console.error("AuthClient is not initialized yet.");
37+
return false;
38+
}
3039
// start the login process and wait for it to finish
3140
await new Promise((resolve) => {
3241
authClient.login({

0 commit comments

Comments
 (0)