sb
03/07/2023, 4:37 PMSET default_transaction_read_only = 'off';
but this doesn't work. It stays read-onlyAless.c06
03/07/2023, 4:58 PMw3center
03/07/2023, 5:08 PMcreate or replace function auth.selectedOrgId() returns uuid as $$
DECLARE
org_id uuid;
BEGIN
RAISE LOG 'The full claims are: %', current_setting('request.jwt.claims', true);
select (nullif(
((current_setting('request.jwt.claims')::jsonb ->> 'user_metadata')::jsonb ->> 'selectedOrgId'),
'')::uuid) into org_id;
RETURN org_id;
END;
$$ language plpgsql;
And this is how the policy looks like:
CREATE POLICY "Access based on user selected org id" ON "public"."org" TO "authenticated" USING (auth.selectedorgid() = "id") WITH CHECK (auth.selectedorgid() = "id");
Any ideas?tom-s3drive
03/07/2023, 5:10 PMchallengeAndVerify
valid TOTP code I get: AuthException(message: An invalid response was received from the upstream server, statusCode: 502)
For an invalid TOTP I get: AuthException(message: Invalid TOTP code entered, statusCode: 400)
I am using hosted Supabase, Is there anything I need to do / configure / enable for TOTP to work?
This Flutter/Dart code demonstrates how I use it:
dart
final res = await supabase.auth.mfa.enroll();
final factorId = res.id;
final qrCodeUri = res.totp.uri;
// render QR code and validate code
await supabase.auth.mfa.challengeAndVerify(factorId: factorId, code: totpCode);
HAHZNFT
03/07/2023, 5:40 PMLukas V
03/07/2023, 5:43 PMconst saveChanges = async () => {
if (!products) return;
let successfulUpdates = 0;
products.forEach(async (product, index) => {
const { data, error } = await supabase
.from('products')
.update({ order_number: index + 1 })
.eq('id', product.id);
// .single();
console.log({
data,
error
});
if (!error) {
successfulUpdates++;
} else {
toast.error(error.message);
}
if (successfulUpdates === products.length) {
toast.success('All updates have succeeded!');
}
});
};
I had no idea what was wrong until I checked that I had products table on read only RLS access ❌ .
I fixed this by adding .single()
and now I receive error correctly, however I have 2 questions:
1. Why I wasn't getting any error message on my original code?
2. Is there any way to get more definitive error messages? At the moment I am receiving this:
{data: null, error: {…}}
data
:
null
error
:
code
:
"PGRST116"
details
:
"Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row"
hint
:
null
message
:
"JSON object requested, multiple (or no) rows returned"
Why is there no hint on why this error was thrown?Cheqo
03/07/2023, 5:48 PMkillerthief
03/07/2023, 5:51 PMtheravenstone
03/07/2023, 5:57 PMeduardos
03/07/2023, 6:23 PMsql
CREATE FUNCTION function_name (params)
RETURNS TABLE (
"column1" "type",
"column2" "type",
)
LANGUAGE "plpgsql"
AS $$
BEGIN
RETURN QUERY
SELECT something here where something else
END;
$$;
Now when I do
js
const { data } = await supabase.rpc('function_name', params);
The type of data
is
ts
data:{
foo: bar;
}[][] | null
How can I make the return type to be just
ts
data:{
foo: bar;
}[] | null
yuqi
03/07/2023, 6:35 PMVik
03/07/2023, 7:24 PMapproved
column for my followers
table. The default value should be based on whether the user_id being followed is private or not.
This is how I've structured my query so far.
ALTER TABLE followers
ADD COLUMN approved BOOLEAN NOT NULL DEFAULT (
CASE WHEN EXISTS (
SELECT 1 FROM profiles WHERE id = followers.user_id AND private = false
) THEN true ELSE false END
);
But I get this error:
Failed to run sql query: cannot use subquery in DEFAULT expression
Vik
03/07/2023, 7:59 PMTomCarnay
03/07/2023, 8:20 PMkillerthief
03/07/2023, 8:30 PMzachblume
03/07/2023, 8:41 PMquery=`SET 'request.jwt.claims' TO '${token}';`;
or what?Rake
03/07/2023, 9:25 PMhachoter
03/07/2023, 10:08 PMsosapps
03/07/2023, 10:14 PMTrevvy
03/07/2023, 11:51 PMmansedan
03/08/2023, 12:36 AMjs
const { data, error } = await supabase.from('events').upsert([
...events,
], { onConflict: 'event_id' })
I had found this github ticket talking about it https://github.com/supabase/postgrest-js/issues/173. So I know it's something to do with the items in the array not all having the same columns. But It seems as though I would have to know which column is missing and create a trigger for possibility? Is that correct?hachoter
03/08/2023, 1:03 AMMathew
03/08/2023, 1:26 AMkingpeppe
03/08/2023, 1:43 AMJinni
03/08/2023, 1:59 AMdebrijja
03/08/2023, 2:29 AM?????
03/08/2023, 2:39 AMmansedan
03/08/2023, 3:05 AMsql
CREATE OR REPLACE FUNCTION update_from_events()
RETURNS TRIGGER AS $$
DECLARE
away_team_mascot text;
home_team_mascot text;
total_score float;
bet_row bets%ROWTYPE;
winning_team VARCHAR(5);
winning_mascot VARCHAR(50);
spread INTEGER;
BEGIN
raise log 'After event update %', NEW.id;
IF NEW.event_status = 'STATUS_FINAL' THEN
raise log 'After event update status %', NEW.event_status;
raise log 'After event BET_ROW BEFORE: %', NEW.id;
-- Loop through all bets that reference this event
FOR bet_row IN SELECT * FROM bets WHERE event = NEW.id LOOP
raise log 'After event update bet_row %', bet_row.id;
-- Calculate total score
total_score := (event.away_score + event.home_score)::float;
END LOOP;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
The table 'bets' has a foreign relation key to 'events' in the 'event' column of bets. Anyone know what my error is by chance?Mattwilson
03/08/2023, 4:45 AMCabtn
03/08/2023, 5:02 AMimport { useEffect } from 'react';
import { ArrowLeftIcon } from '@heroicons/react/outline';
import { useUser, useSupabaseClient } from '@supabase/auth-helpers-react';
import { Auth, ThemeSupa } from '@supabase/auth-ui-react';
import Image from 'next/image';
import Link from 'next/link';
import { useRouter } from 'next/router';
import config from '../config/index.json';
import { getURL } from '../utils/utils';
const Login = () => {
const supabaseClient = useSupabaseClient();
const { login } = config;
const router = useRouter();
const user = useUser();
useEffect(() => {
if (user) {
router.replace('/create-character');
}
}, [router, user]);
if (!user)
return (
<div className="flex min-h-screen bg-background">
<div className="w-1/3 flex flex-col justify-between max-w-lg p-3 m-auto border-primary">
<div className="flex flex-col space-y-4">
<div className={'flex top-10'}>
<ArrowLeftIcon className={'h-6 w-6 text-primary pr-2'} />
<Link className={'text-button'} href="/">
Back to Home Page
</Link>
</div>
<p className={'text-white'}>{login.description}</p>
<Auth
supabaseClient={supabaseClient}
providers={['google', 'facebook']}
redirectTo={getURL()}
......
}