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

Guide/Help #19

Open
kraegpoeth opened this issue Sep 22, 2024 · 1 comment
Open

Guide/Help #19

kraegpoeth opened this issue Sep 22, 2024 · 1 comment

Comments

@kraegpoeth
Copy link

How to use this when i need prefix on my queries? I have setup multitenancy with prefix, but i cannot get this to work in liveview. I keep on getting ERROR 42P01 (undefined_table) relation "users" does not exist
which makes sense because i need to look in the tenant_prefix.users table instead. I'm new to elixir so sorry for any noob questions!

@kraegpoeth
Copy link
Author

Well i figured out how to do it via finalize_query, but now i think that this evolves into a change request. Because i need to return user from fetch_subject, but how can i modify the socket in fetch_subject?

it works now with this, but that is only thanks to Process.dict, which it what Vnet.Tenant.set_tenant stores tenant in.

      """
      Adds the tenant prefix to the query
      """

      @impl true
      def finalize_query(query, resolution_context) do
        prefix = Vnet.Tenant.prefix()
        query |> Ecto.Query.put_query_prefix(prefix)
      end

      @doc
      """
      Fetches the current user from the session token.
      Also sets the tenant in Process dictionary for finalize_query to use
      """

      @impl true
      def fetch_subject(socket, session) do
        Vnet.Tenant.set_tenant(session["subdomain"])
        Vnet.Users.get_user_by_session_token(session["user_token"])
      end```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant