© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4mo ago•
26 replies
Floppy Disk

JS SDK query call produces different results

I ran same query:
const { data: userOrgPermissions } = await supabaseUser
                .from('user_organization_role')
                .select('*, role_based_organization_access_control(*)')
                .eq('organization_id', 1)
                .eq('user_id', "xxx")
                .maybeSingle()
                .throwOnError()
const { data: userOrgPermissions } = await supabaseUser
                .from('user_organization_role')
                .select('*, role_based_organization_access_control(*)')
                .eq('organization_id', 1)
                .eq('user_id', "xxx")
                .maybeSingle()
                .throwOnError()

In Edge function and on the client, on the client I'm getting result I need and on the edge function I get null. I'm thinking it might be because of RLS but in my edge function I'm creating my client following way:
export const createSupabaseUserClient = (userToken: string) => createClient<Database>(
    ENV.SUPABASE_URL ?? '',
    ENV.SUPABASE_ANON_KEY ?? '',
    {
        global: {
            headers: { Authorization: userToken },
        },
    }
)

export const getUserTokenFromHonoRequest = (req: HonoRequest) => {
    const authHeader = req.header('Authorization')
    if (!authHeader) throw new Error('No Authorization header')
    const token = authHeader.replace('Bearer ', '')
    return token;
}

export const createSupabaseUserClientFromHonoRequest = (req: HonoRequest) => {
    const userToken = getUserTokenFromHonoRequest(req)
    return createSupabaseUserClient(userToken)
}
export const createSupabaseUserClient = (userToken: string) => createClient<Database>(
    ENV.SUPABASE_URL ?? '',
    ENV.SUPABASE_ANON_KEY ?? '',
    {
        global: {
            headers: { Authorization: userToken },
        },
    }
)

export const getUserTokenFromHonoRequest = (req: HonoRequest) => {
    const authHeader = req.header('Authorization')
    if (!authHeader) throw new Error('No Authorization header')
    const token = authHeader.replace('Bearer ', '')
    return token;
}

export const createSupabaseUserClientFromHonoRequest = (req: HonoRequest) => {
    const userToken = getUserTokenFromHonoRequest(req)
    return createSupabaseUserClient(userToken)
}

So this function should behave exactly same as if was called on the client, yet it doesnt
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

JS SDK - UNION ALL
SupabaseSSupabase / help-and-questions
2mo ago
Order by in js sdk
SupabaseSSupabase / help-and-questions
4y ago
Supabase JS query question
SupabaseSSupabase / help-and-questions
13mo ago
SQL command instead of js sdk
SupabaseSSupabase / help-and-questions
4mo ago