[15주차] 최종프로젝트 : Trigger 등록, SQL Editor, Supabase Auth, Schema Visualizer
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