From 2825ded7c0ef0bd95f4628ec3f1a0903d477ce42 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Fri, 6 Mar 2026 00:55:36 +0100 Subject: [PATCH] Clean --- .../answers/add-compatibility-question-button.tsx | 2 +- web/components/auth-context.tsx | 1 + web/hooks/use-questions.ts | 8 ++++---- web/lib/api.ts | 9 +-------- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/web/components/answers/add-compatibility-question-button.tsx b/web/components/answers/add-compatibility-question-button.tsx index 75a1acce..407ff3b5 100644 --- a/web/components/answers/add-compatibility-question-button.tsx +++ b/web/components/answers/add-compatibility-question-button.tsx @@ -131,7 +131,7 @@ function CreateCompatibilityModalContent(props: { const data = { question: question, options: generateJson(), - } + } as any const newQuestion = await api('create-compatibility-question', data) debug('create-compatibility-question', newQuestion, data) const q = newQuestion?.question diff --git a/web/components/auth-context.tsx b/web/components/auth-context.tsx index 73397147..6dd6c263 100644 --- a/web/components/auth-context.tsx +++ b/web/components/auth-context.tsx @@ -105,6 +105,7 @@ function useAndSetupFirebaseUser() { } export const FirebaseUserContext = createContext(undefined) + export const AuthContext = createContext(undefined) // function getSupabaseAuthCall() { diff --git a/web/hooks/use-questions.ts b/web/hooks/use-questions.ts index d5b8ef52..f6e58f7b 100644 --- a/web/hooks/use-questions.ts +++ b/web/hooks/use-questions.ts @@ -1,8 +1,8 @@ import {Row} from 'common/supabase/utils' import {sortBy} from 'lodash' import {useEffect, useState} from 'react' +import {useFirebaseUser} from 'web/hooks/use-firebase-user' import {usePersistentInMemoryState} from 'web/hooks/use-persistent-in-memory-state' -import {useUser} from 'web/hooks/use-user' import {api} from 'web/lib/api' import {useLocale} from 'web/lib/locale' import { @@ -97,14 +97,14 @@ export const useFRQuestionsWithAnswerCount = () => { export const useCompatibilityQuestionsWithAnswerCount = (keyword?: string) => { const {locale} = useLocale() - const user = useUser() + const firebaseUser = useFirebaseUser() const [compatibilityQuestions, setCompatibilityQuestions] = usePersistentInMemoryState< QuestionWithCountType[] >([], `compatibility-questions-with-count`) const [isLoading, setIsLoading] = useState(true) async function refreshCompatibilityQuestions() { - if (!user) return + if (!firebaseUser) return setIsLoading(true) return api('get-compatibility-questions', {locale, keyword}).then((res) => { setCompatibilityQuestions(res.questions) @@ -114,7 +114,7 @@ export const useCompatibilityQuestionsWithAnswerCount = (keyword?: string) => { useEffect(() => { refreshCompatibilityQuestions() - }, [user, locale, keyword]) + }, [firebaseUser, locale, keyword]) return { refreshCompatibilityQuestions, diff --git a/web/lib/api.ts b/web/lib/api.ts index 41faf4b0..0b965ab0 100644 --- a/web/lib/api.ts +++ b/web/lib/api.ts @@ -11,14 +11,7 @@ export async function api

(path: P, params: APIParams

= {}) try { if (authed) { - if (auth.currentUser === undefined) { - // Auth hasn't resolved yet — this is a bug in the caller, not a recoverable state - console.error( - `api('${path}') called before auth resolved — check the calling hook/component`, - ) - throw new APIError(401, 'Auth not resolved yet') - } - + await auth.authStateReady() if (auth.currentUser === null) { // User is definitely not logged in console.error(`api('${path}') called while unauthenticated`)