feat: gate homepage entry buttons by login state

This commit is contained in:
light committed 2026-11-07 11:17:50 +08:00
1 parent b124d070cb
commit 1d31de4796
1 file changed
+29 -2
+29 -2
View File
@@ -1146,8 +1146,7 @@
if (lightboxItem && lightboxItem.skillId) params.set("skill", lightboxItem.skillId);
if (lightboxIndustry.name) params.set("industry", lightboxIndustry.name);
const target = "/generate" + (params.toString() ? "?" + params.toString() : "");
const loggedIn = !!localStorage.getItem("access_token");
window.location.href = loggedIn ? target : "/login/?redirect=" + encodeURIComponent(target);
goEntry(target);
}
function closeLightbox() {
@@ -1366,6 +1365,34 @@
window.clearTimeout(resizeTimer);
resizeTimer = window.setTimeout(measure, 120);
});
function isLoggedIn() {
return !!localStorage.getItem("access_token");
}
function goEntry(target) {
const dest = target || "/generate";
if (isLoggedIn()) {
window.location.href = dest;
return;
}
const params = new URLSearchParams({ v: "20261107", redirect: dest });
window.location.href = "/login/?" + params.toString();
}
document.querySelectorAll("a.pill--login, a.pill--signup").forEach(function (link) {
link.addEventListener("click", function (event) {
event.preventDefault();
goEntry("/generate");
});
});
document.querySelectorAll('a[href="/generate"]').forEach(function (link) {
link.addEventListener("click", function (event) {
event.preventDefault();
goEntry(link.getAttribute("href") || "/generate");
});
});
})();
</script>
</body>