Skip to content

Commit cc56795

Browse files
committed
vsfgrgr
1 parent 432c9f5 commit cc56795

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

Assets/js/auth.js

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,54 @@ export function setupOtpInputs() {
2323
}
2424

2525
// Request OTP from server (using GET)
26+
// Request OTP from server (using JSONP workaround)
2627
export async function requestOtp() {
27-
const email = DOM.loginEmail.value.trim();
28-
29-
if (!email || !/^\S+@\S+\.\S+$/.test(email)) {
30-
await showAlert('error', 'Invalid Email', 'Please enter a valid email address');
31-
return false;
32-
}
28+
const email = DOM.loginEmail.value.trim();
29+
30+
if (!email || !/^\S+@\S+\.\S+$/.test(email)) {
31+
await showAlert('error', 'Invalid Email', 'Please enter a valid email address');
32+
return false;
33+
}
3334

34-
try {
35-
const url = `${CONFIG.googleScriptUrl}?action=requestOtp&email=${encodeURIComponent(email)}`;
36-
const response = await fetch(url);
37-
const result = await response.json();
38-
39-
if (result.status === 'success') {
40-
DOM.emailForm.classList.add('hidden');
41-
DOM.otpForm.classList.remove('hidden');
42-
DOM.otpEmailDisplay.textContent = email;
43-
return true;
44-
} else {
45-
await showAlert('error', 'Error', result.message || 'Failed to send OTP');
46-
return false;
47-
}
48-
} catch (error) {
49-
console.error('OTP request error:', error);
50-
await showAlert('error', 'Network Error', 'Failed to connect to server');
51-
return false;
52-
}
35+
try {
36+
// Use JSONP approach
37+
const callbackName = `jsonp_${Date.now()}`;
38+
const url = `${CONFIG.googleScriptUrl}?action=requestOtp&email=${encodeURIComponent(email)}&callback=${callbackName}`;
39+
40+
return new Promise((resolve) => {
41+
window[callbackName] = (response) => {
42+
delete window[callbackName];
43+
44+
if (response.status === 'success') {
45+
DOM.emailForm.classList.add('hidden');
46+
DOM.otpForm.classList.remove('hidden');
47+
DOM.otpEmailDisplay.textContent = email;
48+
resolve(true);
49+
} else {
50+
showAlert('error', 'Error', response.message || 'Failed to send OTP');
51+
resolve(false);
52+
}
53+
};
54+
55+
// Create script tag to make JSONP request
56+
const script = document.createElement('script');
57+
script.src = url;
58+
document.body.appendChild(script);
59+
60+
// Fallback timeout
61+
setTimeout(() => {
62+
if (window[callbackName]) {
63+
delete window[callbackName];
64+
showAlert('error', 'Timeout', 'Server response timed out');
65+
resolve(false);
66+
}
67+
}, 10000);
68+
});
69+
} catch (error) {
70+
console.error('OTP request error:', error);
71+
await showAlert('error', 'Network Error', 'Failed to connect to server');
72+
return false;
73+
}
5374
}
5475

5576
// Verify OTP with server (using GET)

Assets/js/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Configuration constants
22
export const CONFIG = {
3-
googleScriptUrl: 'https://script.google.com/macros/s/AKfycbxhAGJ4zbZdxMkOC6-wdg0ujPeFRVGvoEVd9exLdUimihdx7r-XSQxSElk2hRJ6Z_wr/exec', // auth
3+
googleScriptUrl: 'https://script.google.com/macros/s/AKfycbwnFQV7ukTBCUgGSjipMreyl4t-Zh3cxX4ARLepZ-k8-YL_qARV7chBXhMKVmVOhZ--/exec', // auth
44
sessionExpiryHours: 1, // Matches GAS session duration
55
otpExpiryMinutes: 5, // Matches GAS OTP duration
66

0 commit comments

Comments
 (0)