fixed weird signin bug

This commit is contained in:
George Powell
2026-02-12 20:24:38 -05:00
parent 290fb06fe9
commit f6652e59a7
5 changed files with 335 additions and 119 deletions

View File

@@ -181,10 +181,17 @@
// Initialize anonymous ID
$effect(() => {
if (!browser) return;
anonymousId = getOrCreateAnonymousId();
// CRITICAL: If user is logged in, ALWAYS use their user ID
// Never use the localStorage anonymous ID for authenticated users
if (user) {
anonymousId = user.id;
} else {
anonymousId = getOrCreateAnonymousId();
}
if ((window as any).umami) {
// Use user id if logged in, otherwise use anonymous id
(window as any).umami.identify(user ? user.id : anonymousId);
(window as any).umami.identify(anonymousId);
}
const statsKey = `bibdle-stats-submitted-${dailyVerse.date}`;
statsSubmitted = localStorage.getItem(statsKey) === "true";
@@ -278,7 +285,7 @@
(async () => {
try {
const response = await fetch(
`/api/submit-completion?anonymousId=${user ? user.id : anonymousId}&date=${dailyVerse.date}`,
`/api/submit-completion?anonymousId=${anonymousId}&date=${dailyVerse.date}`,
);
const result = await response.json();
console.log("Stats response:", result);
@@ -308,7 +315,7 @@
async function submitStats() {
try {
const payload = {
anonymousId: user ? user.id : anonymousId,
anonymousId: anonymousId, // Already set correctly in $effect above
date: dailyVerse.date,
guessCount: guesses.length,
};
@@ -477,32 +484,34 @@
<SearchInput bind:searchQuery {guessedIds} {submitGuess} />
</div>
{:else}
<WinScreen
{grade}
{statsData}
{correctBookId}
{handleShare}
{copyToClipboard}
bind:copied
{statsSubmitted}
guessCount={guesses.length}
reference={dailyVerse.reference}
onChapterGuessCompleted={() => {
chapterGuessCompleted = true;
const key = `bibdle-chapter-guess-${dailyVerse.reference}`;
const saved = localStorage.getItem(key);
if (saved) {
const data = JSON.parse(saved);
const match =
dailyVerse.reference.match(/\s(\d+):/);
const correctChapter = match
? parseInt(match[1], 10)
: 1;
chapterCorrect =
data.selectedChapter === correctChapter;
}
}}
/>
<div class="animate-fade-in-up animate-delay-400">
<WinScreen
{grade}
{statsData}
{correctBookId}
{handleShare}
{copyToClipboard}
bind:copied
{statsSubmitted}
guessCount={guesses.length}
reference={dailyVerse.reference}
onChapterGuessCompleted={() => {
chapterGuessCompleted = true;
const key = `bibdle-chapter-guess-${dailyVerse.reference}`;
const saved = localStorage.getItem(key);
if (saved) {
const data = JSON.parse(saved);
const match =
dailyVerse.reference.match(/\s(\d+):/);
const correctChapter = match
? parseInt(match[1], 10)
: 1;
chapterCorrect =
data.selectedChapter === correctChapter;
}
}}
/>
</div>
{/if}
<div class="animate-fade-in-up animate-delay-600">