Skip to content

An AI-powered search engine with a generative UI

fix: address PR review comments

Yoshiki Miura0824a4142fac
diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts
index b98b1bec..66a73034 100644
--- a/app/api/chat/route.ts
+++ b/app/api/chat/route.ts
@@ -84,7 +84,7 @@ export async function POST(req: Request) {
message,
model: selectedModel,
chatId,
- userId: userId,
+ userId: userId, // userId is guaranteed to be non-null after authentication check above
trigger,
messageId,
abortSignal
diff --git a/hooks/use-auth-check.tsx b/hooks/use-auth-check.tsx
index 9a4a538e..0dec583b 100644
--- a/hooks/use-auth-check.tsx
+++ b/hooks/use-auth-check.tsx
@@ -9,9 +9,11 @@ export function useAuthCheck() {
const [loading, setLoading] = useState(true)
useEffect(() => {
+ // Create a single Supabase client instance for this effect
+ const supabase = createClient()
+
const checkAuth = async () => {
try {
- const supabase = createClient()
const {
data: { session }
} = await supabase.auth.getSession()
@@ -26,8 +28,7 @@ export function useAuthCheck() {
checkAuth()
- // Subscribe to auth changes
- const supabase = createClient()
+ // Subscribe to auth changes using the same client instance
const {
data: { subscription }
} = supabase.auth.onAuthStateChange((event, session) => {