mrboutte
05/15/2022, 5:07 PMpayment_method
table with the following SQL
sql
SELECT
EXISTS(
SELECT
*
FROM
payment_method
INNER JOIN account ON account.id = payment_method.account
WHERE
account.account_owner = auth.uid()
);
☝️ this works fine in the sequel editor, but when I try to create a policy with it — I get back Error adding policy: syntax error at or near "SELECT"
mrboutte
05/15/2022, 5:13 PMSELECT
and only provide the EXISTS(<SQL>)
statementmrboutte
05/15/2022, 6:12 PMts
export const fetchPaymentMethodsInfoServerSide = async (
ctx: GetServerSidePropsContext,
accountId: number
) => {
try {
const { data: paymentMethodInfo, error } = await supabaseServerClient(ctx)
.from<definitions['payment_method']>('payment_method')
.select('*')
.eq('account', accountId)
if (error) {
console.error('whoops', error)
return Promise.reject(error)
}
return paymentMethodInfo
} catch (error) {
console.log(
'todo: hook up sentry for fetchPaymentMethodsInfoServerSide',
error
)
}
}
I'm seeing the following error:
infinite recursion detected in policy for relation "payment_method"
mrboutte
05/15/2022, 6:53 PMmrboutte
05/15/2022, 7:51 PMsql
CREATE FUNCTION can_user_fetch_payment_methods(_user_id uuid) RETURNS bool AS $$
SELECT
EXISTS(
SELECT
1
FROM
payment_method
INNER JOIN account ON account.id = payment_method.account
WHERE
account.account_owner = _user_id
);
$$ LANGUAGE sql SECURITY DEFINER;
and now in my policy I just check
can_user_fetch_payment_methods(uid())
burggraf
05/15/2022, 9:45 PMburggraf
05/15/2022, 9:47 PMmrboutte
05/17/2022, 1:04 PMmrboutte
05/17/2022, 1:06 PM