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()

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)
}

So this function should behave exactly same as if was called on the client, yet it doesnt
Was this page helpful?