error while Querying foreign tables - JS

I received an error while getting user data from user table , user_id is linked to users.auth.id .

error :
{error: {code: PGRST200, details: null, hint: Verify that 'users' and 'user_id' exist in the schema 'public' and that there is a foreign key relationship between them. If a new relationship was created, try reloading the schema cache., message: Could not find a relationship between 'users' and 'user_id' in the schema cache}} 
code :
import { serve } from "https://deno.land/std@0.131.0/http/server.ts"
import { createClient } from "https://esm.sh/@supabase/supabase-js@2.0.0";
console.log("Hello from Functions!")
const SUPABASE_URL = Deno.env.get("SUPABASE_URL");
const SUPABASE_ANON_KEY = Deno.env.get("SUPABASE_ANON_KEY");
serve(async (req) => {
  const { user_id } = await req.json()


  const supabase = createClient(
    SUPABASE_URL!,
    SUPABASE_ANON_KEY!,
    {
      global: {
        headers: { Authorization: req.headers.get("Authorization")! },
      },
    },
  );

  const { data, error } = await supabase
  .from("users")
  .select('*,user_id(id)')
  .eq("user_id", user_id)
  .limit(1)
  .single();
  if(error)  return new Response(
    JSON.stringify({error:error}),
    { headers: { "Content-Type": "application/json" } },
  ) 

  return new Response(
    JSON.stringify(data),
    { headers: { "Content-Type": "application/json" } },
  )
})
Was this page helpful?