Recent Posts
Recent Comments
Archives
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 코딩테스트
- Next
- vercel
- 모던자바스크립트
- 코드카타
- js
- CORS
- 스파르타코딩클럽
- supabase
- git
- useRouter
- auth
- 내일배움캠프
- 초기셋팅
- 모던 자바스크립트
- error
- React
- 코테
- 최적화
- 프로젝트 셋팅
- array정적메서드
- deep dive
- 프로그래머스
- domain
- 티스토리챌린지
- 자주 까먹는
- nextjs
- 셋팅
- 오블완
- TailwindCSS
- Today
- Total
도록
supabase.auth 이용하기 본문
배경
- supabase.auth를 통해 인증할 때, supabase.public.users 테이블에 데이터를 자동으로 insert 하기를 원함
방법
1. users 테이블 생성
2. sql editor에서 trigger 함수 생성
-- 1. 기존 트리거 삭제
drop trigger if exists on_auth_user_created on auth.users;
-- 2. 트리거 함수 수정
create or replace function public.handle_new_auth_user()
returns trigger as $$
declare
new_json json;
provider text;
provider_id text;
name text;
picture text;
begin
begin
-- 필드 추출
provider := NEW.raw_app_meta_data ->> 'provider';
provider_id := NEW.raw_user_meta_data ->> 'provider_id';
name := NEW.raw_user_meta_data ->> 'name';
picture := NEW.raw_user_meta_data ->> 'picture';
-- 삽입
insert into public.user (uid, email, type, nick, profile, social_id)
values (NEW.id, NEW.email, provider, name, picture, provider_id);
exception when others then
new_json := row_to_json(NEW);
raise exception 'User Insert Error: %, NEW: %', SQLERRM, new_json::text;
end;
return new;
end;
$$ language plpgsql security definer;
-- 3. 트리거 걸기
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_auth_user();
'Today I Learned > in dev' 카테고리의 다른 글
네이버 채널 알림, 모두 다 한번에 끄기 (feat. 크롬 익스텐션) (0) | 2025.05.21 |
---|---|
supabase auth에는 무슨 값이 들어있을까? (1) | 2025.05.15 |
supabase, 정지된 프로젝트 복원하기 (0) | 2025.05.07 |
[vite] tailwindcss v4.1 설치 오류 | Type 'Plugin<any>[]' is not assignable to type 'PluginOption' (0) | 2025.04.16 |
[css] content-visibility : 사용자에게 노출되는 화면부터 그리기 (0) | 2025.01.23 |