tevrocsdk 0.1.79 → 0.1.81
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/package.json +1 -1
- package/tevroc-sdk.esm.js +819 -153
- package/tevroc-sdk.min.js +51 -51
- package/tevroc-sdk.umd.js +692 -23
package/tevroc-sdk.umd.js
CHANGED
|
@@ -3659,6 +3659,7 @@ var Tevroc = (() => {
|
|
|
3659
3659
|
subscribeGoogleLogin: () => subscribeGoogleLogin
|
|
3660
3660
|
});
|
|
3661
3661
|
function emitGoogleLogin(user, err2 = null) {
|
|
3662
|
+
debugAuth("Emitting login result", { success: Boolean(user), error: err2?.message || null });
|
|
3662
3663
|
googleListeners.forEach((cb) => {
|
|
3663
3664
|
try {
|
|
3664
3665
|
cb(user, err2);
|
|
@@ -3668,13 +3669,15 @@ var Tevroc = (() => {
|
|
|
3668
3669
|
});
|
|
3669
3670
|
}
|
|
3670
3671
|
function subscribeGoogleLogin(cb) {
|
|
3672
|
+
debugAuth("Listener subscribed", { count: googleListeners.length + 1 });
|
|
3671
3673
|
googleListeners.push(cb);
|
|
3672
3674
|
return () => {
|
|
3673
3675
|
const i4 = googleListeners.indexOf(cb);
|
|
3674
3676
|
if (i4 !== -1) googleListeners.splice(i4, 1);
|
|
3677
|
+
debugAuth("Listener unsubscribed", { count: googleListeners.length });
|
|
3675
3678
|
};
|
|
3676
3679
|
}
|
|
3677
|
-
var capacitorPluginsPromise, tauriWebviewWindowPromise, getCapacitorPlugins, getTauriWebviewWindow, googleInitialized, googleListeners, authWindowRef, authCleanupTimer, authMessageListener, closeAllTauriWebviews, cleanupAuthWindow, handleCallback, initializeGoogleLogin, createGoogleLogin;
|
|
3680
|
+
var capacitorPluginsPromise, tauriWebviewWindowPromise, getCapacitorPlugins, debugAuth, debugAuthWarn, debugAuthError, getTauriWebviewWindow, googleInitialized, googleListeners, authWindowRef, authCleanupTimer, authMessageListener, closeAllTauriWebviews, cleanupAuthWindow, handleCallback, initializeGoogleLogin, createGoogleLogin;
|
|
3678
3681
|
var init_useGoogleAuth = __esm({
|
|
3679
3682
|
"src/services/useGoogleAuth.js"() {
|
|
3680
3683
|
init_usePlatform();
|
|
@@ -3683,6 +3686,9 @@ var Tevroc = (() => {
|
|
|
3683
3686
|
capacitorPluginsPromise ??= Promise.all([Promise.resolve().then(() => (init_esm(), esm_exports)), Promise.resolve().then(() => (init_esm2(), esm_exports2))]).then(([appModule, browserModule]) => ({ App: appModule.App, Browser: browserModule.Browser }));
|
|
3684
3687
|
return capacitorPluginsPromise;
|
|
3685
3688
|
};
|
|
3689
|
+
debugAuth = (...args) => debugLog("[tevrocsdk][google-auth]", ...args);
|
|
3690
|
+
debugAuthWarn = (...args) => debugWarn("[tevrocsdk][google-auth]", ...args);
|
|
3691
|
+
debugAuthError = (...args) => debugError("[tevrocsdk][google-auth]", ...args);
|
|
3686
3692
|
getTauriWebviewWindow = async () => {
|
|
3687
3693
|
tauriWebviewWindowPromise ??= Promise.resolve().then(() => (init_webviewWindow(), webviewWindow_exports)).then((module) => module.WebviewWindow);
|
|
3688
3694
|
return tauriWebviewWindowPromise;
|
|
@@ -3721,6 +3727,7 @@ var Tevroc = (() => {
|
|
|
3721
3727
|
}
|
|
3722
3728
|
};
|
|
3723
3729
|
cleanupAuthWindow = async () => {
|
|
3730
|
+
debugAuth("Cleaning up auth window", { hasWindow: Boolean(authWindowRef), isTauri, isCapacitor });
|
|
3724
3731
|
if (authCleanupTimer) {
|
|
3725
3732
|
clearInterval(authCleanupTimer);
|
|
3726
3733
|
authCleanupTimer = null;
|
|
@@ -3764,11 +3771,15 @@ var Tevroc = (() => {
|
|
|
3764
3771
|
};
|
|
3765
3772
|
handleCallback = async (url) => {
|
|
3766
3773
|
try {
|
|
3774
|
+
debugAuth("Callback received", { hasUrl: Boolean(url), hasToken: Boolean(url?.includes("token=")) });
|
|
3767
3775
|
await cleanupAuthWindow();
|
|
3768
|
-
if (!url?.includes("token="))
|
|
3776
|
+
if (!url?.includes("token=")) {
|
|
3777
|
+
debugAuthWarn("Callback did not include a token");
|
|
3778
|
+
return;
|
|
3779
|
+
}
|
|
3769
3780
|
const params = new URLSearchParams(url.split("?")[1]);
|
|
3770
3781
|
const token = params.get("token");
|
|
3771
|
-
|
|
3782
|
+
debugAuth("Verifying provider token", { tokenPresent: Boolean(token) });
|
|
3772
3783
|
const res = await fetch(
|
|
3773
3784
|
"https://www.googleapis.com/oauth2/v3/userinfo",
|
|
3774
3785
|
{
|
|
@@ -3778,6 +3789,7 @@ var Tevroc = (() => {
|
|
|
3778
3789
|
}
|
|
3779
3790
|
);
|
|
3780
3791
|
const googleUser = await res.json();
|
|
3792
|
+
debugAuth("Provider profile received", { idPresent: Boolean(googleUser.sub), emailPresent: Boolean(googleUser.email) });
|
|
3781
3793
|
const profile = {
|
|
3782
3794
|
id: googleUser.sub,
|
|
3783
3795
|
firstName: googleUser.given_name,
|
|
@@ -3791,19 +3803,26 @@ var Tevroc = (() => {
|
|
|
3791
3803
|
localStorage.setItem("idToken", token);
|
|
3792
3804
|
emitGoogleLogin(profile, null);
|
|
3793
3805
|
} catch (err2) {
|
|
3806
|
+
debugAuthError("Callback failed", err2);
|
|
3794
3807
|
emitGoogleLogin(null, err2);
|
|
3795
3808
|
}
|
|
3796
3809
|
};
|
|
3797
3810
|
initializeGoogleLogin = async () => {
|
|
3798
|
-
if (googleInitialized)
|
|
3811
|
+
if (googleInitialized) {
|
|
3812
|
+
debugAuth("Already initialized");
|
|
3813
|
+
return;
|
|
3814
|
+
}
|
|
3799
3815
|
googleInitialized = true;
|
|
3816
|
+
debugAuth("Initializing listeners", { isCapacitor, isTauri });
|
|
3800
3817
|
if (isCapacitor) {
|
|
3818
|
+
debugAuth("Registering Capacitor appUrlOpen listener");
|
|
3801
3819
|
const { App: App2 } = await getCapacitorPlugins();
|
|
3802
3820
|
App2.addListener("appUrlOpen", (event) => {
|
|
3803
3821
|
handleCallback(event.url);
|
|
3804
3822
|
});
|
|
3805
3823
|
}
|
|
3806
3824
|
if (isTauri) {
|
|
3825
|
+
debugAuth("Registering Tauri deep-link listener");
|
|
3807
3826
|
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
3808
3827
|
await listen2("deep-link://open-url", async (event) => {
|
|
3809
3828
|
let url = event.payload;
|
|
@@ -3820,19 +3839,20 @@ var Tevroc = (() => {
|
|
|
3820
3839
|
appName = "Tevroc",
|
|
3821
3840
|
serviceUrl = "https://tevrocsoftapi.netlify.app"
|
|
3822
3841
|
} = {}) => {
|
|
3823
|
-
|
|
3824
|
-
debugLog(isCapacitor, isTauri);
|
|
3842
|
+
debugAuth("Creating login", { appId, appName, serviceUrl, isCapacitor, isTauri });
|
|
3825
3843
|
await initializeGoogleLogin();
|
|
3826
|
-
let authUrl = `${serviceUrl}/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
3844
|
+
let authUrl = `${serviceUrl}/auth/google/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
3827
3845
|
if (isCapacitor) {
|
|
3846
|
+
debugAuth("Opening mobile auth browser");
|
|
3828
3847
|
const { Browser: Browser3 } = await getCapacitorPlugins();
|
|
3829
3848
|
await Browser3.open({ url: authUrl });
|
|
3830
3849
|
return;
|
|
3831
3850
|
}
|
|
3832
3851
|
if (isTauri) {
|
|
3852
|
+
debugAuth("Opening desktop auth window");
|
|
3833
3853
|
const WebviewWindow2 = await getTauriWebviewWindow();
|
|
3834
3854
|
await closeAllTauriWebviews();
|
|
3835
|
-
const url = `${serviceUrl}/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
3855
|
+
const url = `${serviceUrl}/auth/google/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
3836
3856
|
const win = new WebviewWindow2("auth", {
|
|
3837
3857
|
url,
|
|
3838
3858
|
title: `${appName} Login`,
|
|
@@ -3843,33 +3863,35 @@ var Tevroc = (() => {
|
|
|
3843
3863
|
});
|
|
3844
3864
|
authWindowRef = win;
|
|
3845
3865
|
win.once("tauri://created", () => {
|
|
3846
|
-
|
|
3866
|
+
debugAuth("Auth window opened");
|
|
3847
3867
|
});
|
|
3848
3868
|
win.once("tauri://error", (e2) => {
|
|
3849
|
-
|
|
3869
|
+
debugAuthError("Auth window error", e2);
|
|
3850
3870
|
});
|
|
3851
3871
|
return;
|
|
3852
3872
|
}
|
|
3853
3873
|
const isLocalhost = true;
|
|
3854
3874
|
const detectedAppId = typeof window !== "undefined" ? window.location.host : appId;
|
|
3855
3875
|
const mode = isLocalhost ? "localhost" : "netlify";
|
|
3856
|
-
const finalUrl = `${serviceUrl}/login?mode=${mode}&app=${encodeURIComponent(
|
|
3876
|
+
const finalUrl = `${serviceUrl}/auth/google/login?mode=${mode}&app=${encodeURIComponent(
|
|
3857
3877
|
detectedAppId
|
|
3858
3878
|
)}&name=${encodeURIComponent(appName)}`;
|
|
3859
3879
|
if (isLocalhost) {
|
|
3880
|
+
debugAuth("Opening web auth popup", { mode, appId: detectedAppId });
|
|
3860
3881
|
const popup = window.open(
|
|
3861
3882
|
finalUrl,
|
|
3862
3883
|
"googleLogin",
|
|
3863
3884
|
"width=500,height=650"
|
|
3864
3885
|
);
|
|
3865
3886
|
if (!popup) {
|
|
3866
|
-
|
|
3887
|
+
debugAuthError("Popup blocked");
|
|
3867
3888
|
}
|
|
3868
3889
|
authWindowRef = popup;
|
|
3869
3890
|
authMessageListener = async (event) => {
|
|
3870
3891
|
const serviceOrigin = new URL(serviceUrl).origin;
|
|
3871
3892
|
if (event.origin !== serviceOrigin) return;
|
|
3872
3893
|
if (event.data?.type === "google-auth") {
|
|
3894
|
+
debugAuth("Received popup auth message", { origin: event.origin });
|
|
3873
3895
|
const token = event.data?.token || null;
|
|
3874
3896
|
const url = token ? `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${token}` : window.location.href;
|
|
3875
3897
|
await handleCallback(url);
|
|
@@ -3888,6 +3910,521 @@ var Tevroc = (() => {
|
|
|
3888
3910
|
}
|
|
3889
3911
|
});
|
|
3890
3912
|
|
|
3913
|
+
// src/services/useFacebookAuth.js
|
|
3914
|
+
var useFacebookAuth_exports = {};
|
|
3915
|
+
__export(useFacebookAuth_exports, {
|
|
3916
|
+
createFacebookLogin: () => createFacebookLogin,
|
|
3917
|
+
initializeFacebookLogin: () => initializeFacebookLogin,
|
|
3918
|
+
subscribeFacebookLogin: () => subscribeFacebookLogin
|
|
3919
|
+
});
|
|
3920
|
+
function emitFacebookLogin(user, err2 = null) {
|
|
3921
|
+
debugAuth2("Emitting login result", { success: Boolean(user), error: err2?.message || null });
|
|
3922
|
+
facebookListeners.forEach((cb) => {
|
|
3923
|
+
try {
|
|
3924
|
+
cb(user, err2);
|
|
3925
|
+
} catch (e2) {
|
|
3926
|
+
debugError("Facebook listener error:", e2);
|
|
3927
|
+
}
|
|
3928
|
+
});
|
|
3929
|
+
}
|
|
3930
|
+
function subscribeFacebookLogin(cb) {
|
|
3931
|
+
debugAuth2("Listener subscribed", { count: facebookListeners.length + 1 });
|
|
3932
|
+
facebookListeners.push(cb);
|
|
3933
|
+
return () => {
|
|
3934
|
+
const i4 = facebookListeners.indexOf(cb);
|
|
3935
|
+
if (i4 !== -1) facebookListeners.splice(i4, 1);
|
|
3936
|
+
debugAuth2("Listener unsubscribed", { count: facebookListeners.length });
|
|
3937
|
+
};
|
|
3938
|
+
}
|
|
3939
|
+
var capacitorPluginsPromise2, tauriWebviewWindowPromise2, getCapacitorPlugins2, debugAuth2, debugAuthWarn2, debugAuthError2, getTauriWebviewWindow2, facebookInitialized, facebookListeners, authWindowRef2, authCleanupTimer2, authMessageListener2, closeAllTauriWebviews2, cleanupAuthWindow2, handleCallback2, initializeFacebookLogin, createFacebookLogin;
|
|
3940
|
+
var init_useFacebookAuth = __esm({
|
|
3941
|
+
"src/services/useFacebookAuth.js"() {
|
|
3942
|
+
init_usePlatform();
|
|
3943
|
+
init_debug();
|
|
3944
|
+
getCapacitorPlugins2 = () => {
|
|
3945
|
+
capacitorPluginsPromise2 ??= Promise.all([Promise.resolve().then(() => (init_esm(), esm_exports)), Promise.resolve().then(() => (init_esm2(), esm_exports2))]).then(([appModule, browserModule]) => ({ App: appModule.App, Browser: browserModule.Browser }));
|
|
3946
|
+
return capacitorPluginsPromise2;
|
|
3947
|
+
};
|
|
3948
|
+
debugAuth2 = (...args) => debugLog("[tevrocsdk][facebook-auth]", ...args);
|
|
3949
|
+
debugAuthWarn2 = (...args) => debugWarn("[tevrocsdk][facebook-auth]", ...args);
|
|
3950
|
+
debugAuthError2 = (...args) => debugError("[tevrocsdk][facebook-auth]", ...args);
|
|
3951
|
+
getTauriWebviewWindow2 = async () => {
|
|
3952
|
+
tauriWebviewWindowPromise2 ??= Promise.resolve().then(() => (init_webviewWindow(), webviewWindow_exports)).then((module) => module.WebviewWindow);
|
|
3953
|
+
return tauriWebviewWindowPromise2;
|
|
3954
|
+
};
|
|
3955
|
+
facebookInitialized = false;
|
|
3956
|
+
facebookListeners = [];
|
|
3957
|
+
authWindowRef2 = null;
|
|
3958
|
+
authCleanupTimer2 = null;
|
|
3959
|
+
authMessageListener2 = null;
|
|
3960
|
+
closeAllTauriWebviews2 = async () => {
|
|
3961
|
+
if (!isTauri) return;
|
|
3962
|
+
const WebviewWindow2 = await getTauriWebviewWindow2();
|
|
3963
|
+
try {
|
|
3964
|
+
if (typeof WebviewWindow2.getAll === "function") {
|
|
3965
|
+
const windows = await WebviewWindow2.getAll();
|
|
3966
|
+
for (const webview of windows || []) {
|
|
3967
|
+
try {
|
|
3968
|
+
if (webview?.label && webview.label !== "main") {
|
|
3969
|
+
await webview.close();
|
|
3970
|
+
}
|
|
3971
|
+
} catch (e2) {
|
|
3972
|
+
debugWarn("Error closing Tauri webview:", e2);
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
} catch (e2) {
|
|
3977
|
+
debugWarn("Error listing Tauri webviews:", e2);
|
|
3978
|
+
}
|
|
3979
|
+
try {
|
|
3980
|
+
const tauriAuthWindow = await WebviewWindow2.getByLabel("auth");
|
|
3981
|
+
if (tauriAuthWindow) {
|
|
3982
|
+
await tauriAuthWindow.close();
|
|
3983
|
+
}
|
|
3984
|
+
} catch (e2) {
|
|
3985
|
+
debugWarn("Error closing Tauri auth window by label:", e2);
|
|
3986
|
+
}
|
|
3987
|
+
};
|
|
3988
|
+
cleanupAuthWindow2 = async () => {
|
|
3989
|
+
debugAuth2("Cleaning up auth window", { hasWindow: Boolean(authWindowRef2), isTauri, isCapacitor });
|
|
3990
|
+
if (authCleanupTimer2) {
|
|
3991
|
+
clearInterval(authCleanupTimer2);
|
|
3992
|
+
authCleanupTimer2 = null;
|
|
3993
|
+
}
|
|
3994
|
+
if (authMessageListener2 && typeof window !== "undefined") {
|
|
3995
|
+
window.removeEventListener("message", authMessageListener2);
|
|
3996
|
+
authMessageListener2 = null;
|
|
3997
|
+
}
|
|
3998
|
+
if (authWindowRef2) {
|
|
3999
|
+
const currentAuthWindow = authWindowRef2;
|
|
4000
|
+
authWindowRef2 = null;
|
|
4001
|
+
try {
|
|
4002
|
+
if (typeof currentAuthWindow?.close === "function") {
|
|
4003
|
+
await currentAuthWindow.close();
|
|
4004
|
+
}
|
|
4005
|
+
} catch (e2) {
|
|
4006
|
+
debugWarn("Error closing auth window:", e2);
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
if (isTauri) {
|
|
4010
|
+
const WebviewWindow2 = await getTauriWebviewWindow2();
|
|
4011
|
+
await closeAllTauriWebviews2();
|
|
4012
|
+
}
|
|
4013
|
+
if (isCapacitor) {
|
|
4014
|
+
try {
|
|
4015
|
+
const { Browser: Browser3 } = await getCapacitorPlugins2();
|
|
4016
|
+
await Browser3.close();
|
|
4017
|
+
} catch (e2) {
|
|
4018
|
+
debugWarn("Error closing Capacitor browser:", e2);
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
if (typeof window !== "undefined" && window !== window.parent) {
|
|
4022
|
+
try {
|
|
4023
|
+
if (authWindowRef2 && typeof authWindowRef2.close === "function") {
|
|
4024
|
+
await authWindowRef2.close();
|
|
4025
|
+
}
|
|
4026
|
+
} catch (e2) {
|
|
4027
|
+
debugWarn("Error closing popup fallback:", e2);
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
};
|
|
4031
|
+
handleCallback2 = async (url) => {
|
|
4032
|
+
try {
|
|
4033
|
+
debugAuth2("Callback received", { hasUrl: Boolean(url), hasToken: Boolean(url?.includes("token=")) });
|
|
4034
|
+
await cleanupAuthWindow2();
|
|
4035
|
+
if (!url?.includes("token=")) {
|
|
4036
|
+
debugAuthWarn2("Callback did not include a token");
|
|
4037
|
+
return;
|
|
4038
|
+
}
|
|
4039
|
+
const params = new URLSearchParams(url.split("?")[1]);
|
|
4040
|
+
const token = params.get("token");
|
|
4041
|
+
debugAuth2("Verifying provider token", { tokenPresent: Boolean(token) });
|
|
4042
|
+
const res = await fetch(
|
|
4043
|
+
`https://graph.facebook.com/me?fields=id,first_name,last_name,email,picture&access_token=${encodeURIComponent(token)}`
|
|
4044
|
+
);
|
|
4045
|
+
if (!res.ok) {
|
|
4046
|
+
throw new Error(`Facebook profile request failed: ${res.status}`);
|
|
4047
|
+
}
|
|
4048
|
+
const facebookUser = await res.json();
|
|
4049
|
+
debugAuth2("Provider profile received", { idPresent: Boolean(facebookUser.id), emailPresent: Boolean(facebookUser.email) });
|
|
4050
|
+
const profile = {
|
|
4051
|
+
id: facebookUser.id,
|
|
4052
|
+
firstName: facebookUser.first_name,
|
|
4053
|
+
lastName: facebookUser.last_name,
|
|
4054
|
+
email: facebookUser.email,
|
|
4055
|
+
photo: facebookUser.picture?.data?.url,
|
|
4056
|
+
accessToken: token
|
|
4057
|
+
};
|
|
4058
|
+
debugLog("Facebook user profile:", profile);
|
|
4059
|
+
localStorage.setItem("user", JSON.stringify(profile));
|
|
4060
|
+
localStorage.setItem("idToken", token);
|
|
4061
|
+
emitFacebookLogin(profile, null);
|
|
4062
|
+
} catch (err2) {
|
|
4063
|
+
debugAuthError2("Callback failed", err2);
|
|
4064
|
+
emitFacebookLogin(null, err2);
|
|
4065
|
+
}
|
|
4066
|
+
};
|
|
4067
|
+
initializeFacebookLogin = async () => {
|
|
4068
|
+
if (facebookInitialized) {
|
|
4069
|
+
debugAuth2("Already initialized");
|
|
4070
|
+
return;
|
|
4071
|
+
}
|
|
4072
|
+
facebookInitialized = true;
|
|
4073
|
+
debugAuth2("Initializing listeners", { isCapacitor, isTauri });
|
|
4074
|
+
if (isCapacitor) {
|
|
4075
|
+
debugAuth2("Registering Capacitor appUrlOpen listener");
|
|
4076
|
+
const { App: App2 } = await getCapacitorPlugins2();
|
|
4077
|
+
App2.addListener("appUrlOpen", (event) => {
|
|
4078
|
+
handleCallback2(event.url);
|
|
4079
|
+
});
|
|
4080
|
+
}
|
|
4081
|
+
if (isTauri) {
|
|
4082
|
+
debugAuth2("Registering Tauri deep-link listener");
|
|
4083
|
+
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
4084
|
+
await listen2("deep-link://open-url", async (event) => {
|
|
4085
|
+
let url = event.payload;
|
|
4086
|
+
if (typeof url === "object") {
|
|
4087
|
+
url = url?.url || url?.payload || null;
|
|
4088
|
+
}
|
|
4089
|
+
if (!url) return;
|
|
4090
|
+
await handleCallback2(url);
|
|
4091
|
+
});
|
|
4092
|
+
}
|
|
4093
|
+
};
|
|
4094
|
+
createFacebookLogin = async ({
|
|
4095
|
+
appId = "tevrocsoft",
|
|
4096
|
+
appName = "Tevroc",
|
|
4097
|
+
serviceUrl = "https://tevrocsoftapi.netlify.app"
|
|
4098
|
+
} = {}) => {
|
|
4099
|
+
debugAuth2("Creating login", { appId, appName, serviceUrl, isCapacitor, isTauri });
|
|
4100
|
+
await initializeFacebookLogin();
|
|
4101
|
+
let authUrl = `${serviceUrl}/auth/facebook/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
4102
|
+
if (isCapacitor) {
|
|
4103
|
+
debugAuth2("Opening mobile auth browser");
|
|
4104
|
+
const { Browser: Browser3 } = await getCapacitorPlugins2();
|
|
4105
|
+
await Browser3.open({ url: authUrl });
|
|
4106
|
+
return;
|
|
4107
|
+
}
|
|
4108
|
+
if (isTauri) {
|
|
4109
|
+
debugAuth2("Opening desktop auth window");
|
|
4110
|
+
const WebviewWindow2 = await getTauriWebviewWindow2();
|
|
4111
|
+
await closeAllTauriWebviews2();
|
|
4112
|
+
const url = `${serviceUrl}/auth/facebook/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
4113
|
+
const win = new WebviewWindow2("auth", {
|
|
4114
|
+
url,
|
|
4115
|
+
title: `${appName} Login`,
|
|
4116
|
+
width: 550,
|
|
4117
|
+
height: 500,
|
|
4118
|
+
resizable: true,
|
|
4119
|
+
center: true
|
|
4120
|
+
});
|
|
4121
|
+
authWindowRef2 = win;
|
|
4122
|
+
win.once("tauri://created", () => {
|
|
4123
|
+
debugAuth2("Auth window opened");
|
|
4124
|
+
});
|
|
4125
|
+
win.once("tauri://error", (e2) => {
|
|
4126
|
+
debugAuthError2("Auth window error", e2);
|
|
4127
|
+
});
|
|
4128
|
+
return;
|
|
4129
|
+
}
|
|
4130
|
+
const isLocalhost = true;
|
|
4131
|
+
const detectedAppId = typeof window !== "undefined" ? window.location.host : appId;
|
|
4132
|
+
const mode = isLocalhost ? "localhost" : "netlify";
|
|
4133
|
+
const finalUrl = `${serviceUrl}/auth/facebook/login?mode=${mode}&app=${encodeURIComponent(
|
|
4134
|
+
detectedAppId
|
|
4135
|
+
)}&name=${encodeURIComponent(appName)}`;
|
|
4136
|
+
if (isLocalhost) {
|
|
4137
|
+
debugAuth2("Opening web auth popup", { mode, appId: detectedAppId });
|
|
4138
|
+
const popup = window.open(
|
|
4139
|
+
finalUrl,
|
|
4140
|
+
"facebookLogin",
|
|
4141
|
+
"width=500,height=650"
|
|
4142
|
+
);
|
|
4143
|
+
if (!popup) {
|
|
4144
|
+
debugAuthError2("Popup blocked");
|
|
4145
|
+
throw new Error("Facebook sign-in popup was blocked. Allow popups and try again.");
|
|
4146
|
+
}
|
|
4147
|
+
authWindowRef2 = popup;
|
|
4148
|
+
authMessageListener2 = async (event) => {
|
|
4149
|
+
const serviceOrigin = new URL(serviceUrl).origin;
|
|
4150
|
+
if (event.origin !== serviceOrigin) return;
|
|
4151
|
+
if (event.data?.type === "facebook-auth") {
|
|
4152
|
+
debugAuth2("Received popup auth message", { origin: event.origin });
|
|
4153
|
+
const token = event.data?.token || null;
|
|
4154
|
+
const url = token ? `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${token}` : window.location.href;
|
|
4155
|
+
await handleCallback2(url);
|
|
4156
|
+
}
|
|
4157
|
+
};
|
|
4158
|
+
window.addEventListener("message", authMessageListener2);
|
|
4159
|
+
authCleanupTimer2 = setInterval(() => {
|
|
4160
|
+
if (popup.closed) {
|
|
4161
|
+
cleanupAuthWindow2().catch(() => {
|
|
4162
|
+
});
|
|
4163
|
+
}
|
|
4164
|
+
}, 500);
|
|
4165
|
+
return;
|
|
4166
|
+
}
|
|
4167
|
+
};
|
|
4168
|
+
}
|
|
4169
|
+
});
|
|
4170
|
+
|
|
4171
|
+
// src/services/useMetaAuth.js
|
|
4172
|
+
var useMetaAuth_exports = {};
|
|
4173
|
+
__export(useMetaAuth_exports, {
|
|
4174
|
+
createMetaLogin: () => createMetaLogin,
|
|
4175
|
+
initializeMetaLogin: () => initializeMetaLogin,
|
|
4176
|
+
subscribeMetaLogin: () => subscribeMetaLogin
|
|
4177
|
+
});
|
|
4178
|
+
function emitMetaLogin(user, err2 = null) {
|
|
4179
|
+
debugAuth3("Emitting login result", { success: Boolean(user), error: err2?.message || null });
|
|
4180
|
+
metaListeners.forEach((cb) => {
|
|
4181
|
+
try {
|
|
4182
|
+
cb(user, err2);
|
|
4183
|
+
} catch (e2) {
|
|
4184
|
+
debugError("Meta listener error:", e2);
|
|
4185
|
+
}
|
|
4186
|
+
});
|
|
4187
|
+
}
|
|
4188
|
+
function subscribeMetaLogin(cb) {
|
|
4189
|
+
debugAuth3("Listener subscribed", { count: metaListeners.length + 1 });
|
|
4190
|
+
metaListeners.push(cb);
|
|
4191
|
+
return () => {
|
|
4192
|
+
const i4 = metaListeners.indexOf(cb);
|
|
4193
|
+
if (i4 !== -1) metaListeners.splice(i4, 1);
|
|
4194
|
+
debugAuth3("Listener unsubscribed", { count: metaListeners.length });
|
|
4195
|
+
};
|
|
4196
|
+
}
|
|
4197
|
+
var capacitorPluginsPromise3, tauriWebviewWindowPromise3, getCapacitorPlugins3, debugAuth3, debugAuthWarn3, debugAuthError3, getTauriWebviewWindow3, metaInitialized, metaListeners, authWindowRef3, authCleanupTimer3, authMessageListener3, closeAllTauriWebviews3, cleanupAuthWindow3, handleCallback3, initializeMetaLogin, createMetaLogin;
|
|
4198
|
+
var init_useMetaAuth = __esm({
|
|
4199
|
+
"src/services/useMetaAuth.js"() {
|
|
4200
|
+
init_usePlatform();
|
|
4201
|
+
init_debug();
|
|
4202
|
+
getCapacitorPlugins3 = () => {
|
|
4203
|
+
capacitorPluginsPromise3 ??= Promise.all([Promise.resolve().then(() => (init_esm(), esm_exports)), Promise.resolve().then(() => (init_esm2(), esm_exports2))]).then(([appModule, browserModule]) => ({ App: appModule.App, Browser: browserModule.Browser }));
|
|
4204
|
+
return capacitorPluginsPromise3;
|
|
4205
|
+
};
|
|
4206
|
+
debugAuth3 = (...args) => debugLog("[tevrocsdk][meta-auth]", ...args);
|
|
4207
|
+
debugAuthWarn3 = (...args) => debugWarn("[tevrocsdk][meta-auth]", ...args);
|
|
4208
|
+
debugAuthError3 = (...args) => debugError("[tevrocsdk][meta-auth]", ...args);
|
|
4209
|
+
getTauriWebviewWindow3 = async () => {
|
|
4210
|
+
tauriWebviewWindowPromise3 ??= Promise.resolve().then(() => (init_webviewWindow(), webviewWindow_exports)).then((module) => module.WebviewWindow);
|
|
4211
|
+
return tauriWebviewWindowPromise3;
|
|
4212
|
+
};
|
|
4213
|
+
metaInitialized = false;
|
|
4214
|
+
metaListeners = [];
|
|
4215
|
+
authWindowRef3 = null;
|
|
4216
|
+
authCleanupTimer3 = null;
|
|
4217
|
+
authMessageListener3 = null;
|
|
4218
|
+
closeAllTauriWebviews3 = async () => {
|
|
4219
|
+
if (!isTauri) return;
|
|
4220
|
+
const WebviewWindow2 = await getTauriWebviewWindow3();
|
|
4221
|
+
try {
|
|
4222
|
+
if (typeof WebviewWindow2.getAll === "function") {
|
|
4223
|
+
const windows = await WebviewWindow2.getAll();
|
|
4224
|
+
for (const webview of windows || []) {
|
|
4225
|
+
try {
|
|
4226
|
+
if (webview?.label && webview.label !== "main") {
|
|
4227
|
+
await webview.close();
|
|
4228
|
+
}
|
|
4229
|
+
} catch (e2) {
|
|
4230
|
+
debugWarn("Error closing Tauri webview:", e2);
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
} catch (e2) {
|
|
4235
|
+
debugWarn("Error listing Tauri webviews:", e2);
|
|
4236
|
+
}
|
|
4237
|
+
try {
|
|
4238
|
+
const tauriAuthWindow = await WebviewWindow2.getByLabel("auth");
|
|
4239
|
+
if (tauriAuthWindow) {
|
|
4240
|
+
await tauriAuthWindow.close();
|
|
4241
|
+
}
|
|
4242
|
+
} catch (e2) {
|
|
4243
|
+
debugWarn("Error closing Tauri auth window by label:", e2);
|
|
4244
|
+
}
|
|
4245
|
+
};
|
|
4246
|
+
cleanupAuthWindow3 = async () => {
|
|
4247
|
+
debugAuth3("Cleaning up auth window", { hasWindow: Boolean(authWindowRef3), isTauri, isCapacitor });
|
|
4248
|
+
if (authCleanupTimer3) {
|
|
4249
|
+
clearInterval(authCleanupTimer3);
|
|
4250
|
+
authCleanupTimer3 = null;
|
|
4251
|
+
}
|
|
4252
|
+
if (authMessageListener3 && typeof window !== "undefined") {
|
|
4253
|
+
window.removeEventListener("message", authMessageListener3);
|
|
4254
|
+
authMessageListener3 = null;
|
|
4255
|
+
}
|
|
4256
|
+
if (authWindowRef3) {
|
|
4257
|
+
const currentAuthWindow = authWindowRef3;
|
|
4258
|
+
authWindowRef3 = null;
|
|
4259
|
+
try {
|
|
4260
|
+
if (typeof currentAuthWindow?.close === "function") {
|
|
4261
|
+
await currentAuthWindow.close();
|
|
4262
|
+
}
|
|
4263
|
+
} catch (e2) {
|
|
4264
|
+
debugWarn("Error closing auth window:", e2);
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
if (isTauri) {
|
|
4268
|
+
const WebviewWindow2 = await getTauriWebviewWindow3();
|
|
4269
|
+
await closeAllTauriWebviews3();
|
|
4270
|
+
}
|
|
4271
|
+
if (isCapacitor) {
|
|
4272
|
+
try {
|
|
4273
|
+
const { Browser: Browser3 } = await getCapacitorPlugins3();
|
|
4274
|
+
await Browser3.close();
|
|
4275
|
+
} catch (e2) {
|
|
4276
|
+
debugWarn("Error closing Capacitor browser:", e2);
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
if (typeof window !== "undefined" && window !== window.parent) {
|
|
4280
|
+
try {
|
|
4281
|
+
if (authWindowRef3 && typeof authWindowRef3.close === "function") {
|
|
4282
|
+
await authWindowRef3.close();
|
|
4283
|
+
}
|
|
4284
|
+
} catch (e2) {
|
|
4285
|
+
debugWarn("Error closing popup fallback:", e2);
|
|
4286
|
+
}
|
|
4287
|
+
}
|
|
4288
|
+
};
|
|
4289
|
+
handleCallback3 = async (url) => {
|
|
4290
|
+
try {
|
|
4291
|
+
debugAuth3("Callback received", { hasUrl: Boolean(url), hasToken: Boolean(url?.includes("token=")) });
|
|
4292
|
+
await cleanupAuthWindow3();
|
|
4293
|
+
if (!url?.includes("token=")) {
|
|
4294
|
+
debugAuthWarn3("Callback did not include a token");
|
|
4295
|
+
return;
|
|
4296
|
+
}
|
|
4297
|
+
const params = new URLSearchParams(url.split("?")[1]);
|
|
4298
|
+
const token = params.get("token");
|
|
4299
|
+
debugAuth3("Verifying provider token", { tokenPresent: Boolean(token) });
|
|
4300
|
+
const res = await fetch(
|
|
4301
|
+
`https://graph.facebook.com/me?fields=id,name,first_name,last_name,email,picture&access_token=${encodeURIComponent(token)}`
|
|
4302
|
+
);
|
|
4303
|
+
if (!res.ok) throw new Error(`Meta profile request failed: ${res.status}`);
|
|
4304
|
+
const metaUser = await res.json();
|
|
4305
|
+
debugAuth3("Provider profile received", { idPresent: Boolean(metaUser.id), emailPresent: Boolean(metaUser.email) });
|
|
4306
|
+
const profile = {
|
|
4307
|
+
id: metaUser.id,
|
|
4308
|
+
name: metaUser.name,
|
|
4309
|
+
firstName: metaUser.first_name,
|
|
4310
|
+
lastName: metaUser.last_name,
|
|
4311
|
+
email: metaUser.email,
|
|
4312
|
+
photo: metaUser.picture?.data?.url,
|
|
4313
|
+
accessToken: token
|
|
4314
|
+
};
|
|
4315
|
+
debugLog("Meta user profile:", profile);
|
|
4316
|
+
localStorage.setItem("user", JSON.stringify(profile));
|
|
4317
|
+
localStorage.setItem("idToken", token);
|
|
4318
|
+
emitMetaLogin(profile, null);
|
|
4319
|
+
} catch (err2) {
|
|
4320
|
+
debugAuthError3("Callback failed", err2);
|
|
4321
|
+
emitMetaLogin(null, err2);
|
|
4322
|
+
}
|
|
4323
|
+
};
|
|
4324
|
+
initializeMetaLogin = async () => {
|
|
4325
|
+
if (metaInitialized) {
|
|
4326
|
+
debugAuth3("Already initialized");
|
|
4327
|
+
return;
|
|
4328
|
+
}
|
|
4329
|
+
metaInitialized = true;
|
|
4330
|
+
debugAuth3("Initializing listeners", { isCapacitor, isTauri });
|
|
4331
|
+
if (isCapacitor) {
|
|
4332
|
+
debugAuth3("Registering Capacitor appUrlOpen listener");
|
|
4333
|
+
const { App: App2 } = await getCapacitorPlugins3();
|
|
4334
|
+
App2.addListener("appUrlOpen", (event) => {
|
|
4335
|
+
handleCallback3(event.url);
|
|
4336
|
+
});
|
|
4337
|
+
}
|
|
4338
|
+
if (isTauri) {
|
|
4339
|
+
debugAuth3("Registering Tauri deep-link listener");
|
|
4340
|
+
const { listen: listen2 } = await Promise.resolve().then(() => (init_event(), event_exports));
|
|
4341
|
+
await listen2("deep-link://open-url", async (event) => {
|
|
4342
|
+
let url = event.payload;
|
|
4343
|
+
if (typeof url === "object") {
|
|
4344
|
+
url = url?.url || url?.payload || null;
|
|
4345
|
+
}
|
|
4346
|
+
if (!url) return;
|
|
4347
|
+
await handleCallback3(url);
|
|
4348
|
+
});
|
|
4349
|
+
}
|
|
4350
|
+
};
|
|
4351
|
+
createMetaLogin = async ({
|
|
4352
|
+
appId = "tevrocsoft",
|
|
4353
|
+
appName = "Tevroc",
|
|
4354
|
+
serviceUrl = "https://tevrocsoftapi.netlify.app"
|
|
4355
|
+
} = {}) => {
|
|
4356
|
+
debugAuth3("Creating login", { appId, appName, serviceUrl, isCapacitor, isTauri });
|
|
4357
|
+
await initializeMetaLogin();
|
|
4358
|
+
const authUrl = `${serviceUrl}/auth/meta/login?mode=mobile&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
4359
|
+
if (isCapacitor) {
|
|
4360
|
+
debugAuth3("Opening mobile auth browser");
|
|
4361
|
+
const { Browser: Browser3 } = await getCapacitorPlugins3();
|
|
4362
|
+
await Browser3.open({ url: authUrl });
|
|
4363
|
+
return;
|
|
4364
|
+
}
|
|
4365
|
+
if (isTauri) {
|
|
4366
|
+
debugAuth3("Opening desktop auth window");
|
|
4367
|
+
const WebviewWindow2 = await getTauriWebviewWindow3();
|
|
4368
|
+
await closeAllTauriWebviews3();
|
|
4369
|
+
const url = `${serviceUrl}/auth/meta/login?mode=desktop&app=${encodeURIComponent(appId)}&name=${encodeURIComponent(appName)}`;
|
|
4370
|
+
const win = new WebviewWindow2("auth", {
|
|
4371
|
+
url,
|
|
4372
|
+
title: `${appName} Login`,
|
|
4373
|
+
width: 550,
|
|
4374
|
+
height: 500,
|
|
4375
|
+
resizable: true,
|
|
4376
|
+
center: true
|
|
4377
|
+
});
|
|
4378
|
+
authWindowRef3 = win;
|
|
4379
|
+
win.once("tauri://created", () => {
|
|
4380
|
+
debugAuth3("Auth window opened");
|
|
4381
|
+
});
|
|
4382
|
+
win.once("tauri://error", (e2) => {
|
|
4383
|
+
debugAuthError3("Auth window error", e2);
|
|
4384
|
+
});
|
|
4385
|
+
return;
|
|
4386
|
+
}
|
|
4387
|
+
const isLocalhost = true;
|
|
4388
|
+
const detectedAppId = typeof window !== "undefined" ? window.location.host : appId;
|
|
4389
|
+
const mode = isLocalhost ? "localhost" : "netlify";
|
|
4390
|
+
const finalUrl = `${serviceUrl}/auth/meta/login?mode=${mode}&app=${encodeURIComponent(
|
|
4391
|
+
detectedAppId
|
|
4392
|
+
)}&name=${encodeURIComponent(appName)}`;
|
|
4393
|
+
if (isLocalhost) {
|
|
4394
|
+
debugAuth3("Opening web auth popup", { mode, appId: detectedAppId });
|
|
4395
|
+
const popup = window.open(
|
|
4396
|
+
finalUrl,
|
|
4397
|
+
"metaLogin",
|
|
4398
|
+
"width=500,height=650"
|
|
4399
|
+
);
|
|
4400
|
+
if (!popup) {
|
|
4401
|
+
debugAuthError3("Popup blocked");
|
|
4402
|
+
throw new Error("Meta sign-in popup was blocked. Allow popups and try again.");
|
|
4403
|
+
}
|
|
4404
|
+
authWindowRef3 = popup;
|
|
4405
|
+
authMessageListener3 = async (event) => {
|
|
4406
|
+
const serviceOrigin = new URL(serviceUrl).origin;
|
|
4407
|
+
if (event.origin !== serviceOrigin) return;
|
|
4408
|
+
if (event.data?.type === "meta-auth") {
|
|
4409
|
+
debugAuth3("Received popup auth message", { origin: event.origin });
|
|
4410
|
+
const token = event.data?.token || null;
|
|
4411
|
+
const url = token ? `${window.location.href}${window.location.href.includes("?") ? "&" : "?"}token=${token}` : window.location.href;
|
|
4412
|
+
await handleCallback3(url);
|
|
4413
|
+
}
|
|
4414
|
+
};
|
|
4415
|
+
window.addEventListener("message", authMessageListener3);
|
|
4416
|
+
authCleanupTimer3 = setInterval(() => {
|
|
4417
|
+
if (popup.closed) {
|
|
4418
|
+
cleanupAuthWindow3().catch(() => {
|
|
4419
|
+
});
|
|
4420
|
+
}
|
|
4421
|
+
}, 500);
|
|
4422
|
+
return;
|
|
4423
|
+
}
|
|
4424
|
+
};
|
|
4425
|
+
}
|
|
4426
|
+
});
|
|
4427
|
+
|
|
3891
4428
|
// src/services/useYocoPayment.js
|
|
3892
4429
|
function emitPaymentStatus(status, err2 = null) {
|
|
3893
4430
|
paymentStatusListeners.forEach((cb) => {
|
|
@@ -3905,18 +4442,18 @@ var Tevroc = (() => {
|
|
|
3905
4442
|
if (i4 !== -1) paymentStatusListeners.splice(i4, 1);
|
|
3906
4443
|
};
|
|
3907
4444
|
}
|
|
3908
|
-
var
|
|
4445
|
+
var capacitorPluginsPromise4, tauriWebviewWindowPromise4, getCapacitorPlugins4, getTauriWebviewWindow4, paymentInitialized, paymentStatusListeners, paymentWindowRef, logs, addLog, handlePaymentCallback, initializePayment, createPayment;
|
|
3909
4446
|
var init_useYocoPayment = __esm({
|
|
3910
4447
|
"src/services/useYocoPayment.js"() {
|
|
3911
4448
|
init_usePlatform();
|
|
3912
4449
|
init_debug();
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
return
|
|
4450
|
+
getCapacitorPlugins4 = () => {
|
|
4451
|
+
capacitorPluginsPromise4 ??= Promise.all([Promise.resolve().then(() => (init_esm(), esm_exports)), Promise.resolve().then(() => (init_esm2(), esm_exports2))]).then(([appModule, browserModule]) => ({ App: appModule.App, Browser: browserModule.Browser }));
|
|
4452
|
+
return capacitorPluginsPromise4;
|
|
3916
4453
|
};
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
return
|
|
4454
|
+
getTauriWebviewWindow4 = async () => {
|
|
4455
|
+
tauriWebviewWindowPromise4 ??= Promise.resolve().then(() => (init_webviewWindow(), webviewWindow_exports)).then((module) => module.WebviewWindow);
|
|
4456
|
+
return tauriWebviewWindowPromise4;
|
|
3920
4457
|
};
|
|
3921
4458
|
paymentInitialized = false;
|
|
3922
4459
|
paymentStatusListeners = [];
|
|
@@ -3958,7 +4495,7 @@ var Tevroc = (() => {
|
|
|
3958
4495
|
if (paymentInitialized) return;
|
|
3959
4496
|
paymentInitialized = true;
|
|
3960
4497
|
if (isCapacitor) {
|
|
3961
|
-
const { App: App2 } = await
|
|
4498
|
+
const { App: App2 } = await getCapacitorPlugins4();
|
|
3962
4499
|
App2.addListener("appUrlOpen", (event) => {
|
|
3963
4500
|
handlePaymentCallback(
|
|
3964
4501
|
event.url,
|
|
@@ -4001,14 +4538,14 @@ var Tevroc = (() => {
|
|
|
4001
4538
|
const paymentUrl = `${basePaymentUrl}?mode=mobile&amount=${cents}&app=${appId}&account=${payAccount}`;
|
|
4002
4539
|
debugLog(basePaymentUrl, paymentUrl);
|
|
4003
4540
|
if (isCapacitor) {
|
|
4004
|
-
const { Browser: Browser3 } = await
|
|
4541
|
+
const { Browser: Browser3 } = await getCapacitorPlugins4();
|
|
4005
4542
|
await Browser3.open({
|
|
4006
4543
|
url: paymentUrl
|
|
4007
4544
|
});
|
|
4008
4545
|
return;
|
|
4009
4546
|
}
|
|
4010
4547
|
if (isTauri) {
|
|
4011
|
-
const WebviewWindow2 = await
|
|
4548
|
+
const WebviewWindow2 = await getTauriWebviewWindow4();
|
|
4012
4549
|
const url = `${basePaymentUrl}?mode=desktop&amount=${cents}&app=${appId}&account=${payAccount}`;
|
|
4013
4550
|
const win = new WebviewWindow2("payment", {
|
|
4014
4551
|
url,
|
|
@@ -26950,6 +27487,8 @@ var Tevroc = (() => {
|
|
|
26950
27487
|
unregisterDebugHandler: () => unregisterDebugHandler
|
|
26951
27488
|
});
|
|
26952
27489
|
init_useGoogleAuth();
|
|
27490
|
+
init_useFacebookAuth();
|
|
27491
|
+
init_useMetaAuth();
|
|
26953
27492
|
init_useYocoPayment();
|
|
26954
27493
|
init_debug();
|
|
26955
27494
|
|
|
@@ -42119,6 +42658,20 @@ var Tevroc = (() => {
|
|
|
42119
42658
|
}
|
|
42120
42659
|
return googleModule;
|
|
42121
42660
|
}
|
|
42661
|
+
var facebookModule = null;
|
|
42662
|
+
async function getFacebookModule() {
|
|
42663
|
+
if (!facebookModule) {
|
|
42664
|
+
facebookModule = await Promise.resolve().then(() => (init_useFacebookAuth(), useFacebookAuth_exports));
|
|
42665
|
+
}
|
|
42666
|
+
return facebookModule;
|
|
42667
|
+
}
|
|
42668
|
+
var metaModule = null;
|
|
42669
|
+
async function getMetaModule() {
|
|
42670
|
+
if (!metaModule) {
|
|
42671
|
+
metaModule = await Promise.resolve().then(() => (init_useMetaAuth(), useMetaAuth_exports));
|
|
42672
|
+
}
|
|
42673
|
+
return metaModule;
|
|
42674
|
+
}
|
|
42122
42675
|
var TevrocError = class extends Error {
|
|
42123
42676
|
constructor(message2, options = {}) {
|
|
42124
42677
|
super(message2);
|
|
@@ -42531,6 +43084,7 @@ var Tevroc = (() => {
|
|
|
42531
43084
|
// base44
|
|
42532
43085
|
loginWithProvider: async (provider, redirectTo, setToken = async () => {
|
|
42533
43086
|
}) => {
|
|
43087
|
+
console.log(client, "loginWithProvider called", { provider, redirectTo });
|
|
42534
43088
|
if (provider === "google") {
|
|
42535
43089
|
const { createGoogleLogin: createGoogleLogin2, subscribeGoogleLogin: subscribeGoogleLogin2 } = await getGoogleModule();
|
|
42536
43090
|
debugLog2(client, {
|
|
@@ -42538,7 +43092,7 @@ var Tevroc = (() => {
|
|
|
42538
43092
|
appId: client.appId,
|
|
42539
43093
|
appName: client.appName
|
|
42540
43094
|
});
|
|
42541
|
-
createGoogleLogin2({
|
|
43095
|
+
await createGoogleLogin2({
|
|
42542
43096
|
serviceUrl: client.serviceUrl,
|
|
42543
43097
|
appId: client.appId,
|
|
42544
43098
|
appName: client.appName
|
|
@@ -42560,12 +43114,100 @@ var Tevroc = (() => {
|
|
|
42560
43114
|
});
|
|
42561
43115
|
}
|
|
42562
43116
|
}
|
|
43117
|
+
if (provider === "facebook") {
|
|
43118
|
+
const { createFacebookLogin: createFacebookLogin2, subscribeFacebookLogin: subscribeFacebookLogin2 } = await getFacebookModule();
|
|
43119
|
+
debugLog2(client, {
|
|
43120
|
+
serviceUrl: client.serviceUrl,
|
|
43121
|
+
appId: client.appId,
|
|
43122
|
+
appName: client.appName
|
|
43123
|
+
});
|
|
43124
|
+
if (redirectTo) {
|
|
43125
|
+
const unsub = subscribeFacebookLogin2(async (user, err2) => {
|
|
43126
|
+
debugLog2(client, "Facebook callback:", user, err2);
|
|
43127
|
+
unsub();
|
|
43128
|
+
if (!user) return;
|
|
43129
|
+
const result = await client.request("/auth/facebook", {
|
|
43130
|
+
method: "POST",
|
|
43131
|
+
body: buildAuthPayload({ accessToken: user.accessToken }, client),
|
|
43132
|
+
auth: false
|
|
43133
|
+
});
|
|
43134
|
+
debugLog2(client, result);
|
|
43135
|
+
await setToken(result.token, result.user);
|
|
43136
|
+
debugLog2(client, "Redirecting to:", redirectTo);
|
|
43137
|
+
window.location.href = redirectTo;
|
|
43138
|
+
});
|
|
43139
|
+
try {
|
|
43140
|
+
await createFacebookLogin2({
|
|
43141
|
+
serviceUrl: client.serviceUrl,
|
|
43142
|
+
appId: client.appId,
|
|
43143
|
+
appName: client.appName
|
|
43144
|
+
});
|
|
43145
|
+
} catch (error) {
|
|
43146
|
+
unsub();
|
|
43147
|
+
throw error;
|
|
43148
|
+
}
|
|
43149
|
+
} else {
|
|
43150
|
+
await createFacebookLogin2({
|
|
43151
|
+
serviceUrl: client.serviceUrl,
|
|
43152
|
+
appId: client.appId,
|
|
43153
|
+
appName: client.appName
|
|
43154
|
+
});
|
|
43155
|
+
}
|
|
43156
|
+
}
|
|
43157
|
+
if (provider === "meta") {
|
|
43158
|
+
const { createMetaLogin: createMetaLogin2, subscribeMetaLogin: subscribeMetaLogin2 } = await getMetaModule();
|
|
43159
|
+
debugLog2(client, {
|
|
43160
|
+
serviceUrl: client.serviceUrl,
|
|
43161
|
+
appId: client.appId,
|
|
43162
|
+
appName: client.appName
|
|
43163
|
+
});
|
|
43164
|
+
if (redirectTo) {
|
|
43165
|
+
const unsub = subscribeMetaLogin2(async (user, err2) => {
|
|
43166
|
+
debugLog2(client, "Meta callback:", user, err2);
|
|
43167
|
+
unsub();
|
|
43168
|
+
if (!user) return;
|
|
43169
|
+
const result = await client.request("/auth/meta", {
|
|
43170
|
+
method: "POST",
|
|
43171
|
+
body: buildAuthPayload({ accessToken: user.accessToken }, client),
|
|
43172
|
+
auth: false
|
|
43173
|
+
});
|
|
43174
|
+
debugLog2(client, result);
|
|
43175
|
+
await setToken(result.token, result.user);
|
|
43176
|
+
debugLog2(client, "Redirecting to:", redirectTo);
|
|
43177
|
+
window.location.href = redirectTo;
|
|
43178
|
+
});
|
|
43179
|
+
try {
|
|
43180
|
+
await createMetaLogin2({
|
|
43181
|
+
serviceUrl: client.serviceUrl,
|
|
43182
|
+
appId: client.appId,
|
|
43183
|
+
appName: client.appName
|
|
43184
|
+
});
|
|
43185
|
+
} catch (error) {
|
|
43186
|
+
unsub();
|
|
43187
|
+
throw error;
|
|
43188
|
+
}
|
|
43189
|
+
} else {
|
|
43190
|
+
await createMetaLogin2({
|
|
43191
|
+
serviceUrl: client.serviceUrl,
|
|
43192
|
+
appId: client.appId,
|
|
43193
|
+
appName: client.appName
|
|
43194
|
+
});
|
|
43195
|
+
}
|
|
43196
|
+
}
|
|
42563
43197
|
},
|
|
42564
43198
|
// extra
|
|
42565
43199
|
googleLogin: (params) => createGoogleLogin(params),
|
|
42566
43200
|
onGoogleLogin: (callback) => {
|
|
42567
43201
|
return subscribeGoogleLogin(callback);
|
|
42568
43202
|
},
|
|
43203
|
+
facebookLogin: (params) => createFacebookLogin(params),
|
|
43204
|
+
onFacebookLogin: (callback) => {
|
|
43205
|
+
return subscribeFacebookLogin(callback);
|
|
43206
|
+
},
|
|
43207
|
+
metaLogin: (params) => createMetaLogin(params),
|
|
43208
|
+
onMetaLogin: (callback) => {
|
|
43209
|
+
return subscribeMetaLogin(callback);
|
|
43210
|
+
},
|
|
42569
43211
|
//
|
|
42570
43212
|
async login(input) {
|
|
42571
43213
|
const body = buildAuthPayload(input, client);
|
|
@@ -42573,6 +43215,33 @@ var Tevroc = (() => {
|
|
|
42573
43215
|
if (result.token) client.setToken(result.token);
|
|
42574
43216
|
return result;
|
|
42575
43217
|
},
|
|
43218
|
+
async loginWithGoogle(input) {
|
|
43219
|
+
const result = await client.request("/auth/google", {
|
|
43220
|
+
method: "POST",
|
|
43221
|
+
body: buildAuthPayload(input, client),
|
|
43222
|
+
auth: false
|
|
43223
|
+
});
|
|
43224
|
+
if (result.token) client.setToken(result.token);
|
|
43225
|
+
return result;
|
|
43226
|
+
},
|
|
43227
|
+
async loginWithFacebook(input) {
|
|
43228
|
+
const result = await client.request("/auth/facebook", {
|
|
43229
|
+
method: "POST",
|
|
43230
|
+
body: buildAuthPayload(input, client),
|
|
43231
|
+
auth: false
|
|
43232
|
+
});
|
|
43233
|
+
if (result.token) client.setToken(result.token);
|
|
43234
|
+
return result;
|
|
43235
|
+
},
|
|
43236
|
+
async loginWithMeta(input) {
|
|
43237
|
+
const result = await client.request("/auth/meta", {
|
|
43238
|
+
method: "POST",
|
|
43239
|
+
body: buildAuthPayload(input, client),
|
|
43240
|
+
auth: false
|
|
43241
|
+
});
|
|
43242
|
+
if (result.token) client.setToken(result.token);
|
|
43243
|
+
return result;
|
|
43244
|
+
},
|
|
42576
43245
|
async logout() {
|
|
42577
43246
|
const result = await client.request("/auth/logout", { method: "POST", body: buildAuthPayload({}, client) });
|
|
42578
43247
|
client.clearToken();
|