From 578be3de2e888b178b49e8c4bef023d1a83b44b2 Mon Sep 17 00:00:00 2001 From: Michael Czechowski Date: Fri, 16 Jan 2026 15:00:13 +0100 Subject: [PATCH] fix: playground back button goes to previous lesson MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Back button in playground now works the same as Previous button on other pages - it navigates to the previous lesson. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- src/app.js | 8 -------- src/auth.js | 23 ++++++++++++++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/app.js b/src/app.js index 9ba2080..bc054d4 100644 --- a/src/app.js +++ b/src/app.js @@ -793,14 +793,6 @@ function nextLesson() { function prevLesson() { const engineState = lessonEngine.getCurrentState(); - const isPlayground = engineState.lesson?.mode === "playground"; - - // In playground mode, "Back" navigates to home - if (isPlayground) { - navigateTo("#"); - return; - } - const prevModuleId = engineState.module?.id; const success = lessonEngine.previousLesson(); if (success) { diff --git a/src/auth.js b/src/auth.js index d229249..2b8fe5b 100644 --- a/src/auth.js +++ b/src/auth.js @@ -52,8 +52,15 @@ export async function handleOAuthCallback() { } } - // Clear the hash after processing - window.history.replaceState(null, "", window.location.pathname); + // Restore the original route (saved before OAuth redirect) + const savedRoute = localStorage.getItem("codeCrispies.oauthReturnRoute"); + if (savedRoute) { + localStorage.removeItem("codeCrispies.oauthReturnRoute"); + window.history.replaceState(null, "", window.location.pathname + savedRoute); + } else { + // No saved route - just clear the hash + window.history.replaceState(null, "", window.location.pathname); + } return true; } catch (e) { @@ -322,8 +329,13 @@ function setupAuthForms() { } }); - // OAuth buttons + // OAuth buttons - save current route before redirect document.getElementById("google-login")?.addEventListener("click", async () => { + // Save current route to restore after OAuth + const currentHash = window.location.hash; + if (currentHash && !currentHash.includes("access_token")) { + localStorage.setItem("codeCrispies.oauthReturnRoute", currentHash); + } const { error } = await authModule?.signInWithGoogle() ?? { error: null }; if (error) { showOAuthError(error.message); @@ -331,6 +343,11 @@ function setupAuthForms() { }); document.getElementById("github-login")?.addEventListener("click", async () => { + // Save current route to restore after OAuth + const currentHash = window.location.hash; + if (currentHash && !currentHash.includes("access_token")) { + localStorage.setItem("codeCrispies.oauthReturnRoute", currentHash); + } const { error } = await authModule?.signInWithGitHub() ?? { error: null }; if (error) { showOAuthError(error.message);