This commit is contained in:
MartinBraquet
2026-03-06 00:55:36 +01:00
parent 69161612f6
commit 2825ded7c0
4 changed files with 7 additions and 13 deletions

View File

@@ -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

View File

@@ -105,6 +105,7 @@ function useAndSetupFirebaseUser() {
}
export const FirebaseUserContext = createContext<FirebaseUser | null | undefined>(undefined)
export const AuthContext = createContext<AuthUser>(undefined)
// function getSupabaseAuthCall() {

View File

@@ -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,

View File

@@ -11,14 +11,7 @@ export async function api<P extends APIPath>(path: P, params: APIParams<P> = {})
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`)