ui: redesign login lobby, fix auth view transition timing
This commit is contained in:
@@ -364,28 +364,45 @@ function evidenceBlock(evidence = []) {
|
||||
return `<section><h2>Evidence</h2><ul class="small-list">${evidence.map((item) => `<li>${escapeHTML(item.quote || item.id)}</li>`).join("")}</ul></section>`;
|
||||
}
|
||||
|
||||
window.handleCredentialResponse = async (response) => {
|
||||
window._tutorGoogleCallback = async (response) => {
|
||||
console.log("[auth] Google callback fired");
|
||||
try {
|
||||
const res = await request("/api/v1/auth/google", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ id_token: response.credential }),
|
||||
});
|
||||
console.log("[auth] Backend login success", res.user?.email);
|
||||
localStorage.setItem("tutor_token", res.token);
|
||||
localStorage.setItem("tutor_user", JSON.stringify(res.user));
|
||||
if (els.loginError) {
|
||||
els.loginError.textContent = "";
|
||||
els.loginError.classList.remove("visible");
|
||||
}
|
||||
renderAuth();
|
||||
} catch (err) {
|
||||
if (els.loginError) els.loginError.textContent = err.message;
|
||||
console.error("[auth] Backend login failed", err);
|
||||
if (els.loginError) {
|
||||
els.loginError.textContent = err.message;
|
||||
els.loginError.classList.add("visible");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (window._tutorPendingGoogleResponse) {
|
||||
window._tutorGoogleCallback(window._tutorPendingGoogleResponse);
|
||||
window._tutorPendingGoogleResponse = null;
|
||||
}
|
||||
|
||||
function renderAuth() {
|
||||
const user = JSON.parse(localStorage.getItem("tutor_user") || "null");
|
||||
const token = localStorage.getItem("tutor_token");
|
||||
console.log("[auth] renderAuth", { hasUser: !!user, hasToken: !!token });
|
||||
if (user && token) {
|
||||
els.loginView.style.display = "none";
|
||||
els.workspaceView.style.display = "grid";
|
||||
els.userInfo.textContent = user.email;
|
||||
setStatus(`Signed in as ${user.email}`);
|
||||
els.userInfo.textContent = user.email || user.name || "User";
|
||||
setStatus(`Signed in as ${user.email || user.name}`);
|
||||
if (els.loginError) els.loginError.classList.remove("visible");
|
||||
} else {
|
||||
els.loginView.style.display = "flex";
|
||||
els.workspaceView.style.display = "none";
|
||||
|
||||
Reference in New Issue
Block a user