Skip to content

Fix null crashes in openAuthModal/openModal and disable auto-popup on password reset#4

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-null-checks-open-auth-modal
Draft

Fix null crashes in openAuthModal/openModal and disable auto-popup on password reset#4
Copilot wants to merge 2 commits intomainfrom
copilot/add-null-checks-open-auth-modal

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

openAuthModal() and openModal() crash with TypeError: Cannot read properties of null when their respective overlay elements are absent from the DOM. Additionally, the page auto-opens the auth modal when a reset_token query param is present, violating the no-auto-popup requirement.

Changes

  • codedost.jsopenAuthModal(): Guard auth-modal-overlay lookup with early return before accessing .style
  • codedost.jsopenModal(): Guard modal-overlay lookup with early return before accessing .classList
  • codedost.html: Comment out the checkPasswordReset IIFE that called openAuthModal() on page load
// openAuthModal — before
document.getElementById('auth-modal-overlay').style.display = 'flex';

// after
const authModalOverlay = document.getElementById('auth-modal-overlay');
if (!authModalOverlay) return;
authModalOverlay.style.display = 'flex';

Same early-return pattern applied to openModal() for modal-overlay.

Original prompt

Problems to Fix:

  1. TypeError: Cannot read properties of null (reading 'style') at codedost.js:37

    • openAuthModal() tries to access document.getElementById('auth-modal-overlay') which may be null
    • Add null checks to prevent crashes
  2. TypeError: Cannot read properties of null (reading 'classList') at codedost.js:1480

    • openModal() tries to access document.getElementById('modal-overlay') without null check
    • Add null checks to prevent crashes
  3. Auto-opening password reset modal at codedost.html:689

    • When page loads with reset_token URL param, it auto-opens auth modal
    • User wants NO auto-popups - disable this auto-trigger
  4. CORS errors from Railway backend

    • Backend trial expired, causing fetch errors to loadUsageCounter()
    • Already disabled in init() but need to keep it disabled

Solution:

  1. Add null checks to openAuthModal() and openModal() functions
  2. Remove/comment auto-open auth modal on password reset (line 689)
  3. Ensure all auto-popups stay disabled in init() function
  4. Test that NO popups appear on page load

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: codedost open krty hen screen pe 2 se 3 popup appear hoty hen one of login , one of certificate generated and one of ypur complete learning path, m chahta hiun ke just wo popup appear na hon baki each and evyrthing whi rhy

Assistant: Perfect! I understand - you want to disable those auto-opening popups and only show them when the user clicks the buttons.

Here's the fix:

Remove Auto-Opening Popups

Find these functions in your codedost.js and comment them out:

1. DISABLE: Auto-show Learning Path Widget

Find this line (around line 200-300):

if (this.userProfile.totalErrors >= 5) {
  this.showLearningPathWidget();
}

Change it to:

// DISABLED: Don't auto-show widget
// if (this.userProfile.totalErrors >= 5) {
//   this.showLearningPathWidget();
// }

2. DISABLE: Auto-show Auth Modal

Find this in the init() function (around line 2100):

const hasAnyKey = ["groq", "gemini", "openrouter"].some((p) =>
  localStorage.getItem(PROVIDERS[p].storageKey),
);
if (!hasAnyKey) setTimeout(openModal, 800);

Change it to:

// DISABLED: Don't auto-show API key modal
// const hasAnyKey = ["groq", "gemini", "openrouter"].some((p) =>
//   localStorage.getItem(PROVIDERS[p].storageKey),
// );
// if (!hasAnyKey) setTimeout(openModal, 800);

3. DISABLE: Any other auto-popups

Search for:

  • showConceptOfDay() - Comment it out
  • openAuthModal() - Comment it out (if auto-called)
  • Any setTimeout(openModal - Comment out

COMPLETE FIX: Minimal Init Function

Replace your init function's end section with this:

(function init() {
  // Load user preferences from localStorage
  const savedMode = localStorage.getItem("cd_mode");
  if (savedMode && ["urdu", "mixed", "english"].includes(savedMode)) {
    currentMode = savedMode;
    const modeBtn = document.querySelector(
      `.mode-btn[data-mode="${savedMode}"]`,
    );
    if (modeBtn) {
      document
        .querySelectorAll(".mode-btn")
        .forEach((b) => b.classList.remove("active"));
      modeBtn.classList.add("active");
    }
  }

  // Load theme preference
  const savedTheme = localStorage.getItem("cd_theme") || "dark";
  currentTheme = savedTheme;
  document.documentElement.setAttribute("data-theme", savedTheme);
  const themeBtn = document.getElementById("theme-toggle");
  if (themeBtn) {
    themeBtn.textContent = savedTheme === "dark" ? "🌙" : "☀️";
    if (savedTheme === "light") themeBtn.classList.add("active");
  }

  const savedLang = localStorage.getItem("cd_lang");
  if (savedLang && LANG_TAGS[savedLang]) {
    currentLang = savedLang;
    document.getElementById("lang-picker").value = savedLang;
    updateLang();
  }

  initExampleChips();
  initModeButtons();
  renderHistory();
  renderPatterns();

  document
    .getElementById("pattern-date-filter")
    .addEventListener("change", filterPatternsByDate);

  // NO AUTO-POPUPS - Users will trigger them manually
  // initStreak();
  // loadUsageCounter();
  initEditorCounter();
  initHistorySwipe();
  // showConceptOfDay();
  
  // Auth UI
  updateAuthUI();
  if (authToken) loadQuotaFromBackend();
})();

NOW YOUR APP WILL:

✅ Open cleanly with NO popups
✅ Show code editor ready to use
✅ Users can click buttons to:

  • 🔑 "Free API Key" button → opens API modal
  • 📚 "Start Learning Path" → opens learning path
  • 👤 "Login" button → opens auth modal

Save and reload - no more auto-popups! 🎉

User: read me repo and than answer

Assistant: Perfect! I've read the CodeDost repository README. Here's a comprehensive summary:


📚 CodeDost Repository Summary

What is CodeDost?

🇵🇰 Pakistan's First AI Coding Tutor — An inte...

This pull request was created from Copilot chat.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
code-dost Ready Ready Preview, Comment May 2, 2026 4:42am

…password reset

Agent-Logs-Url: https://github.com/sheraz91-ops/CodeDost/sessions/bab8c659-1cca-4d11-ac80-6915ac5fe3d1

Co-authored-by: sheraz91-ops <220106830+sheraz91-ops@users.noreply.github.com>
Copilot AI changed the title [WIP] Add null checks to prevent crashes in modal functions Fix null crashes in openAuthModal/openModal and disable auto-popup on password reset May 2, 2026
Copilot AI requested a review from sheraz91-ops May 2, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants