Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom schema implementations don't work with the supabase ssr package #749

Open
2 tasks done
anindosarker opened this issue Mar 11, 2024 · 4 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@anindosarker
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I tried creating a client with my custom schema named tasks. But it throws errors and doesn't work.

Errors in the editor
Screenshot_20240311_123332

Code for the request:

import { createClient } from "@/utils/supabase/client"; // this is the client with ssr as mentioned above

const supabase = createClient();
const { data, error } = await supabase.from("tb_worker").select();
console.log("🚀 ~ getData ~ error:\n", error);

Errors in the console when I try to request for the data

{
    "code": "42P01",
    "details": null,
    "hint": null,
    "message": "relation \"public.tb_worker\" does not exist"
}

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a sample nextjs project with supabase from the docs
  2. Download sample database types for any project with custom schema.
  3. Update either the browser client or the server client with the custom schema like this
import { createBrowserClient } from "@supabase/ssr";
import { Database } from "../types/database";

export const createClient = () =>
  createBrowserClient<Database>(
    process.env.NEXT_PUBLIC_SUPABASE_URL!,
    process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
    {
      db: {
        schema: "tasks", // I'm using custom schema named tasks. You can change it to your schema name
      },
    }
  );
  1. At this stage, you'll get typescript errors.
  2. You can still try to query for the data from the custom schema and will get the same errors.
import { createClient } from "@/utils/supabase/client"; // this is the client with ssr as mentioned above

const supabase = createClient();
const { data, error } = await supabase.from("tb_worker").select();
console.log("🚀 ~ getData ~ error:\n", error);

Expected behavior

Should get the data. It works perfectly with the supabase js library. Example:
page.tsx

"use client";

import { createSupbaseClent } from "@/utils/supabase/supabaseClient";
import { useEffect, useState } from "react";

export default function Page() {
  const [notes, setNotes] = useState<any[] | null>(null);
  const supabase = createSupbaseClent();

  useEffect(() => {
    const getData = async () => {
      const { data, error } = await supabase.from("tb_worker").select();
      console.log("🚀 ~ getData ~ error:\n", error);
      setNotes(data);
    };
    getData();
  }, []);

  if (!notes) return <div>Loading ...</div>;

  return (
    <>
      <pre>{JSON.stringify(notes, null, 2)}</pre>
    </>
  );
}

System information

  • OS: [linux: Manjaro]
  • Version of supabase-js: [2.39.7]
  • Version of Node.js: [20]

Additional context

I've checked wherther it's an issue of Typescript types generated by the database type generation in the supabase dashboard. Maybe this bug is also related to that as well.

@anindosarker anindosarker added the bug Something isn't working label Mar 11, 2024
@nsenthilkumar
Copy link

This seems to still be an issue

@somesebastian
Copy link

I have the same problem, somebody knows the solution?

@anindosarker
Copy link
Author

I have the same problem, somebody knows the solution?

@somesebastian
I have a solution. I created separate clients for each schema. Used any as the type to stop typescript errors. You can modify the database.ts file that you can generate from the supabase dashboard. But it is tedious so I skipped it.

This doesn't seem the best solution but it works for now.

@somesebastian
Copy link

I have the same problem, somebody knows the solution?

@somesebastian I have a solution. I created separate clients for each schema. Used any as the type to stop typescript errors. You can modify the database.ts file that you can generate from the supabase dashboard. But it is tedious so I skipped it.

This doesn't seem the best solution but it works for now.

@anindosarker I'll test it, thank you for the solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants