• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

Should you extend Supabase Auth with User Profiles?

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
Регистрация
1 Мар 2015
Сообщения
1,481
Баллы
155
Supabase Auth already has an Auth Users table.


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



The image might be blurry.

If you visit the project in your Supabase Account, you can check your Auth table of the project.

If you wanted to add additional data to your a User table, it's likely you've wondered ?

Should you create your own, separate profiles (or users) table in Supabase and link it with the Supabase Auth Users table?
OR

Should you extend the existing Supabase Auth Users table?
Supabase’s recommended pattern is to create a separate profiles (or users) table in the public schema rather than altering the built-in auth.users table.

The auth.users table (in the auth schema) is managed internally and isn’t exposed via the auto-generated API.

Supabase maintainers explicitly advise

“It is not recommended to modify the schema of auth.users; the best way is to create a users (or profiles) table in the public schema and add any custom user-related data there.”
Linking Profiles to auth.users


Make your public.profiles (or public.users) table use the same UUID as primary key and reference auth.users(id)


-- Create profiles table
create table public.profiles (
id uuid primary key references auth.users(id) on delete cascade,
full_name text,
bio text,
avatar_url text
);

-- Enable RLS
alter table public.profiles enable row level security;

-- Policy for INSERT
create policy "Users can insert own profile"
on public.profiles for insert
with check (auth.uid() = id);

-- Policy for UPDATE
create policy "Users can update own profile"
on public.profiles for update
using (auth.uid() = id);

-- Policy for SELECT
create policy "Users can view own profile"
on public.profiles for select
using (auth.uid() = id);
Automatic Profile Creation on Signup


To automatically create a profile row when a new user signs up (via email or OAuth), use a Postgres trigger on auth.users


-- 1. Create the function
create or replace function public.handle_new_user()
returns trigger
language plpgsql security definer set search_path = public
as $$
begin
insert into public.profiles (id) values (NEW.id);
return NEW;
end;
$$;

-- 2. Create the trigger on the Supabase Auth table
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();


Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу