Mar 4 (edited) • Supabase
How I connected Supabase auth.users to my own public.users table
Hello engineers,
For the past few days I’ve been trying to set up Supabase as my backend‑as‑a‑service. It turns out it’s a bit more complicated than I expected (surprise :)).
The goal is to set up a solid foundation for future development. I want to create tables for users and tenants. Supabase already has a table for users — auth.users. That table is for authentication: when a user registers in the app, a record is created there. But if I want to connect that user to other tables, I need to access the user’s id from the auth.users table, and it looks straightforward: just use auth.users(id).
For example, if I want to create a table public.users (for storing additional data for each user), I can do this:
CREATE TABLE IF NOT EXISTS public.users (
id UUID PRIMARY KEY REFERENCES auth.users (id) ON DELETE CASCADE,
-- additional data for a user
full_name TEXT,
avatar_url TEXT,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW(),
tenant_id UUID REFERENCES public.tenants (id) ON DELETE CASCADE
);
Now the user is fully linked to the app logic, while still being backed by Supabase Auth.
2
0 comments
Karol Szykula
3
How I connected Supabase auth.users to my own public.users table
powered by
EngineeringTech
skool.com/szykulatech-3240
We focus on JS/TS, React, Next.js, Supabase, shadcn/ui, Tailwind CSS, and deployments on Netlify. We focus on fast learning.
Build your own community
Bring people together around your passion and get paid.
Powered by