Supabase Auth, Trigger 등록, SQL Editor, Schema Visualizer
Trigger 등록
: 수파베이스의 auth의 users 테이블의 id를 public의 custom_users의 uid와 연결하고 싶은 상황. 현재 키 맵핑은 되어 있음.
결국, 새로운 사용자가 회원가입을 해서 auth users의 테이블에 새로 등록이 되면 그 등록된 데이터를 자동으로 custom_users의 uid로 연결해서 데이터를 넣어주는 작업을 하려면 trigger를 사용해야한다. 단, 유의할점은 supabase auth와 관련된 triggersms 아래 브라우저단에서는 할 수 없고, SQL Editor를 통해 직접 넣어줘어야 한다. 이제 이 에디터에 넣어야 할 함수(trigger function)은 아래와 같다.
-- 트리거 함수 생성
CREATE OR REPLACE FUNCTION public.handle_new_auth_user()
RETURNS TRIGGER AS $$
BEGIN
-- public.users 테이블에 새로운 행 추가
INSERT INTO public.custom_users (uid)
VALUES (NEW.id);
// NEW는 새롭게 추가된 데이터 전체를 뜻한다.
RETURN NEW;
END;
$$ LANGUAGE plpgsql security definer;
-- 트리거 설정
CREATE TRIGGER add_user_to_public_users
AFTER INSERT ON auth.users
FOR EACH ROW
EXECUTE FUNCTION public.handle_new_auth_user();


Schema Visualizer
ERD 즉, 데이터간 관계를 보려면 아래화면과 같이 Schema Visualizer를 보면 된다.

++ 추가
Part Three: Policies | Supabase Docs
Note that auth.getSession reads the auth token and the unencoded session data from the local storage medium. It doesn't send a request back to the Supabase Auth server unless the local session is expired. You should never trust the unencoded session data i
supabase.com
Row Level Security | Supabase Docs
Keep in mind that a JWT is not always "fresh". In the example above, even if you remove a user from a team and update the app_metadata field, that will not be reflected using auth.jwt() until the user's JWT is refreshed. Also, if you are using Cookies for
supabase.com
Postgres Changes | Supabase Docs
RLS policies are not applied to DELETE statements, because there is no way for Postgres to verify that a user has access to a deleted record. When RLS is enabled and replica identity is set to full on a table, the old record contains only the primary key(s
supabase.com
'부트캠프 개발일지 2023-2024 > Bootcamp 생활기록' 카테고리의 다른 글
[16주차] 최종프로젝트 : 실시간 알림 기능 - 알림시간 라이브러리 date-fns (0) | 2024.01.17 |
---|---|
[16주차] 최종프로젝트 : 리액트 라이프사이클, 체크박스(all포함), NextUI (0) | 2024.01.17 |
[15주차] 최종 프로젝트 : Realtime-Postgres Changes 이용하여 알림기능만들기(1) 기능테스트 (1) | 2024.01.11 |
[15주차] next.js와 App router 에 대한 이해 : 최적화, type import 컨벤션, Link, StaticSite Generation (1) | 2024.01.10 |
[15주차] 최종 프로젝트 : supabase 데이터 관계형 table 만들기 (1) | 2024.01.09 |