-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth-fix.js
More file actions
71 lines (61 loc) · 2.74 KB
/
Copy pathauth-fix.js
File metadata and controls
71 lines (61 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* ============================================================
AUTH POPUP FIX — auth-fix.js
Drop this after main.js on any page that still uses the old
inline auth popup (#auth-popup) with Sign In / Sign Up buttons.
The root issue: main.js now routes signInBtn/signUpBtn to
/account, but openAuth() is still called on some pages
(e.g. chat.html sendMessage()). This makes the popup appear
but the login/signup buttons inside it do nothing visible
because they rely on the old inline Supabase flow.
FIX STRATEGY:
- Override openAuth() to redirect straight to /account
- Keep the old popup hidden entirely (it's dead UI)
- Pages that call openAuth() will now redirect properly
============================================================ */
(function patchAuth() {
function fromParam() {
return encodeURIComponent(window.location.pathname + window.location.search);
}
// Persist current page as redirect target for after sign-in.
// Skip auth pages themselves so we don't create a redirect loop.
const thisPage = window.location.pathname + window.location.search;
const authPages = ['/signin', '/signup', '/account', '/oauth/'];
if (!authPages.some(p => thisPage.startsWith(p))) {
sessionStorage.setItem('360_auth_redirect', thisPage);
}
// Override the global openAuth used by sendMessage, chat, etc.
window.openAuth = function(mode) {
const dest = mode === "signup"
? "/signup?from=" + fromParam()
: "/signin?from=" + fromParam();
window.location.href = dest;
};
// Hide the legacy popup permanently — it's replaced by /account
const popup = document.getElementById("auth-popup");
if (popup) {
popup.style.display = "none";
popup.classList.add("hidden");
}
// Patch any inline auth buttons that might still be wired directly
const loginBtn = document.getElementById("auth-login-btn");
const signupBtn = document.getElementById("auth-signup-btn");
const closeBtn = document.getElementById("auth-close-btn");
if (loginBtn) loginBtn.onclick = () => window.openAuth("signin");
if (signupBtn) signupBtn.onclick = () => window.openAuth("signup");
if (closeBtn) closeBtn.onclick = () => {};
// Patch github/google OAuth buttons inside the popup
const ghBtn = document.getElementById("github-login");
const ggBtn = document.getElementById("google-login");
if (ghBtn) ghBtn.onclick = () => {
supabaseClient.auth.signInWithOAuth({
provider: "github",
options: { redirectTo: window.location.origin + "/signin?from=" + fromParam() }
});
};
if (ggBtn) ggBtn.onclick = () => {
supabaseClient.auth.signInWithOAuth({
provider: "google",
options: { redirectTo: window.location.origin + "/signin?from=" + fromParam() }
});
};
})();