
โ Security Definer View๋?
๋ทฐ๋ฅผ ์กฐํํ ์ฌ์ฉ์์ ๊ถํ์ด ์๋๋ผ, ๋ทฐ๋ฅผ ๋ง๋ ์์ ์์ ๊ถํ์ ๊ธฐ์ค์ผ๋ก ์๋ณธ ํ ์ด๋ธ์ ์กฐํํ๋ ๋ทฐ
RLS๋ฅผ ์ค์ ํ๊ณ ๋ค๋ฅธ ๋ณด์ ์กฐ์น๋ฅผ ์ทจํ๋ค๊ณ ํ๋๋ผ๋ ๋ง์ฝ View๊ฐ Security Definer View๋ก ์ค์ ๋์ด ์๋ค๋ฉด, ๋ชจ๋ ๊ฒ ๋ฌด์ฉ์ง๋ฌผ์ด ๋๋ค.
์ฌ์ฉ์ ๊ถํ์ผ๋ก RLS๋ฅผ ์ ์ฉ์์ผ ์ ๊ทผํ๊ฒ ํ๋ ค๋ฉด View์ ๋ค์ ์ฝ๋๋ง ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค.
WITH (security_invoker = true)
CREATE OR REPLACE VIEW community_post_list_view
WITH (security_invoker = true)
AS
SELECT
posts.post_id,
posts.title,
posts.created_at,
topics.name AS topic,
profiles.name AS author,
profiles.avatar AS author_avatar,
profiles.username AS author_username,
posts.upvotes,
topics.slug AS topic_slug,
(SELECT EXISTS (SELECT 1 FROM public.post_upvotes WHERE post_upvotes.post_id = posts.post_id AND post_upvotes.profile_id = auth.uid())) AS is_upvoted
FROM posts
INNER JOIN topics USING (topic_id)
INNER JOIN profiles USING (profile_id);'๐งฉ SQL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| SQL - RLS(Row Level Security) with Drizzle (0) | 2026.07.23 |
|---|---|
| SQL - Supabase PostgreSQL - Cron Job (0) | 2026.07.16 |
| SQL - PostgreSQL - RLS(Row Level Security) (0) | 2026.07.15 |
| SQL - PostgreSQL - CREATE OR REPLACE๊ฐ ๊ฐ๋ฅํ ๋์ ๋ถ๊ฐ๋ฅํ ๋ (0) | 2026.07.13 |
| SQL - PostgreSQL - SET search_path = ''๋ฅผ ์ฌ์ฉํ๋ ์ด์ ? (0) | 2026.07.13 |