fix query parser

This commit is contained in:
Nate Kelley 2025-05-28 16:30:25 -06:00
parent 12d0d68629
commit b5131ce125
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 36 additions and 44 deletions

View File

@ -10,9 +10,9 @@ export async function GET(request: NextRequest) {
if (user && !user?.is_anonymous) {
return NextResponse.json(currencies);
} else {
return NextResponse.error();
}
return NextResponse.error();
}
const currencies = [

View File

@ -13,7 +13,7 @@ export default async function EmbedLayout({ children }: { children: React.ReactN
<BusterAssetsProvider>
<BusterPosthogProvider>
<main className="bg-background h-screen max-h-screen min-h-screen w-full">
<>{children}</>
{children}
</main>
</BusterPosthogProvider>
</BusterAssetsProvider>

View File

@ -3,7 +3,8 @@ import { userQueryKeys } from '@/api/query_keys/users';
import type { QueryClient, queryOptions } from '@tanstack/react-query';
export const isQueryStale = (
options: ReturnType<typeof queryOptions<unknown, RustApiError, unknown>>,
// biome-ignore lint/suspicious/noExplicitAny: It really doesn't matter what the type is here
options: ReturnType<typeof queryOptions<any, RustApiError, any>>,
queryClient: QueryClient
): boolean => {
const queryState = queryClient.getQueryState(options.queryKey);

View File

@ -1,57 +1,48 @@
'use server';
import type { Session, User } from '@supabase/supabase-js';
import type { Database } from './database.types';
import type { createClient } from './server';
import { createClient } from './server';
import { signInWithAnonymousUser } from './signIn';
type PromiseType<T extends Promise<unknown>> = T extends Promise<infer U> ? U : never;
export type UseSupabaseUserContextType = PromiseType<ReturnType<typeof getSupabaseUserContext>>;
export const getSupabaseUserContext = async (supabase: ReturnType<typeof createClient>) => {
let userContext: { user: User | null; session: Session | null } = {
user: null,
session: null
};
export const getSupabaseUserContext = async (preemptiveRefreshMinutes = 5) => {
const supabase = await createClient();
try {
let sessionData = await supabase.auth.getSession();
// Get the session first
let { data: sessionData } = await supabase.auth.getSession();
// If no session exists, try to refresh
if (!sessionData.session) {
const refreshedSessionData = await supabase.auth.refreshSession();
// Check if we need to refresh the session
if (sessionData.session) {
const refreshedSessionData = (await refreshSessionIfNeeded(
supabase,
sessionData.session,
preemptiveRefreshMinutes
)) as Awaited<ReturnType<typeof refreshSessionIfNeeded>>;
// If session was refreshed, get the updated session
if (refreshedSessionData?.session) {
// Replace the entire sessionData object to avoid type issues
sessionData = refreshedSessionData;
}
// If session was refreshed, get the updated session
if (refreshedSessionData && 'session' in refreshedSessionData) {
// Replace the entire sessionData object to avoid type issues
sessionData = refreshedSessionData;
}
// If we still don't have a session, sign in anonymously
if (!sessionData.session) {
const anonymousSignInResult = await signInWithAnonymousUser(supabase);
if (anonymousSignInResult.data?.session) {
sessionData = {
data: {
session: anonymousSignInResult.data.session,
user: anonymousSignInResult.data.user
},
error: null
};
}
}
userContext = {
user: sessionData.data.session?.user || null,
session: sessionData.data.session || null
};
} catch (error) {
console.error('Error getting user context:', error);
}
return userContext;
// Get user data
const { data: userData } = await supabase.auth.getUser();
if (!userData.user) {
const { session: anonSession } = await signInWithAnonymousUser();
return {
user: anonSession?.user || null,
accessToken: anonSession?.access_token
};
}
const user = userData.user;
const accessToken = sessionData.session?.access_token;
const refreshToken = sessionData.session?.refresh_token;
return { user, accessToken, refreshToken };
};
/**