Skip to content

Commit 7a2e0ed

Browse files
authored
[Unity] Apple and Facebook logins (#1981)
1 parent fb0cb67 commit 7a2e0ed

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

.changeset/nasty-pears-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/unity-js-bridge": patch
3+
---
4+
5+
[Unity] Added Facebook and Apple providers

packages/unity-js-bridge/src/thirdweb-bridge.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ThirdwebSDK, ChainIdOrName } from "@thirdweb-dev/sdk";
55
import { ThirdwebStorage } from "@thirdweb-dev/storage";
66
import {
77
DAppMetaData,
8+
EmbeddedWalletOauthStrategy,
89
SmartWalletConfig,
910
walletIds,
1011
} from "@thirdweb-dev/wallets";
@@ -281,15 +282,31 @@ class ThirdwebBridge implements TWBridge {
281282
chainId: chainIdNumber,
282283
authResult,
283284
});
284-
} else if (authOptionsParsed.authProvider === 1) {
285-
// GoogleManaged
286-
const googleWindow = this.openGoogleSignInWindow();
287-
if (!googleWindow) {
288-
throw new Error("Failed to open google login window");
285+
} else if (authOptionsParsed.authProvider < 4) {
286+
// OAuth
287+
let authProvider: EmbeddedWalletOauthStrategy;
288+
switch (authOptionsParsed.authProvider) {
289+
case 1:
290+
authProvider = "google";
291+
break;
292+
case 2:
293+
authProvider = "apple";
294+
break;
295+
case 3:
296+
authProvider = "facebook";
297+
break;
298+
default:
299+
throw new Error(
300+
"Invalid auth provider: " + authOptionsParsed.authProvider,
301+
);
302+
}
303+
const popupWindow = this.openPopupWindow();
304+
if (!popupWindow) {
305+
throw new Error("Failed to open login window");
289306
}
290307
const authResult = await embeddedWallet.authenticate({
291-
strategy: "google",
292-
openedWindow: googleWindow,
308+
strategy: authProvider,
309+
openedWindow: popupWindow,
293310
closeOpenedWindow: (openedWindow) => {
294311
openedWindow.close();
295312
},
@@ -298,7 +315,7 @@ class ThirdwebBridge implements TWBridge {
298315
chainId: chainIdNumber,
299316
authResult,
300317
});
301-
} else if (authOptionsParsed.authProvider === 2) {
318+
} else if (authOptionsParsed.authProvider === 4) {
302319
// CustomAuth
303320
const authResult = await embeddedWallet.authenticate({
304321
strategy: "jwt",
@@ -627,10 +644,10 @@ class ThirdwebBridge implements TWBridge {
627644
return localWallet;
628645
}
629646

630-
public openGoogleSignInWindow() {
647+
public openPopupWindow() {
631648
const win = window.open("", undefined, "width=350, height=500");
632649
if (win) {
633-
win.document.title = "Sign In - Google Accounts";
650+
win.document.title = "Sign In - OAuth";
634651
win.document.body.innerHTML = `
635652
<svg class="loader" viewBox="0 0 50 50">
636653
<circle

0 commit comments

Comments
 (0)