我研究了有关StackOverflow、github问题的各种解决方案,包括supabase、supabase/postgrest、postgRESTPostgREST/postgrest,并搜索了不一致之处。但到目前为止,这些解决方案都没有奏效。
代码按照预期工作,但只要我打开Supabase上的RLS就可以了。请求将返回以下406错误。
export const supabase = createClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY)
const { data, error } = await supabase.from('profiles').select('*').eq('id', userId).maybeSingle()
// const { data, error } = await supabase.from('profiles').select('*').eq('id', userId).limit(1).single() // works when RLS disabled
// const { data, error } = await supabase.from('profiles').select('*').eq('id', userId).single() // works when RLS disabled
RLS之前的反应
{
"id": "123-123-1241-1231",
"created_at": "2022-06-10T03:59:22.751125+00:00",
"is_subscribed": false,
"interval": null,
"email": "test@example.com"
}
打开RLS后的响应
{
"message": "JSON object requested, multiple (or no) rows returned",
"details": "Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row"
}
我尝试过重新加载模式,重新实现策略,但到目前为止还没有一个在工作。
我有一个“配置文件”表,它的"id“列引用了"auth.users.id”。
策略的目标角色目前是"anon“,但我也尝试过”身份验证“。
(uid() = id)
我还试图将表名改为“概要文件”(复数),而不是“配置文件”,但没有运气。
发布于 2022-06-18 01:00:26
从苏巴塞的不和中得到帮助解决了这个问题。
谢谢不和的@garyaustin
!
,我的猜测是,在进行调用时,您没有登录用户(或jwt)。如果将策略设置为true和anon,则确认在呼叫点没有登录用户。
我正在使用NextJS和cookie在客户端请求上附加,但是没有在服务器端请求上附加jwt。
包含令牌和RLS使用的是authenticated
角色。
supabase.auth.setAuth(access_token)
https://stackoverflow.com/questions/72654424
复制相似问题