moarwick
04/14/2023, 2:04 AMrommyarb
04/14/2023, 2:44 AM@supabase/auth-helpers-react
in my Next.js project. I have initialized the supabase client url & anon key in the _app.tsx
file, and in my React function component I can call supabase client like this:
js
import { useSupabaseClient } from '@supabase/auth-helpers-react';
function MyComponent(){
const supabase = useSupabaseClient(); // <-- like this
// ...
}
What if I want to use this initialized supabase client outside function component? Do I need to initialize new supabase client with createClient()
?
Thank you in advance!bombillazo
04/14/2023, 2:49 AMinvitations
table. Inserting to this table isn't as simple as adding a record. It requires checking the inviter has access to the target account, the status field in that table cannot be set directly by the client, and ideally some related tables are updated as well so it preferably runs in a transaction.
Ideally, one has an API endpoint POST
for /invitations
to handle this internally, but that is controlled by PostgREST.
So the question is, what is the Supabase "philosophy" or approach to using the Supabase client on the front-end? Is it mainly used for simple actions and Admin CRUD operations with the PostREST endpoints, and for "real" backend logic one has to define RPCs? Should I define another "equivalent" parallel operation to simulate what I would normally do as a POST invitations
endpoint in a regular API?nnet3
04/14/2023, 2:50 AMdperolio
04/14/2023, 4:02 AM97549189629636608
And is there any way to set a field value to default as Date.now()
(i.e. the number of milliseconds elapsed since the epoch, which is defined as the midnight at the beginning of January 1, 1970, UTC.)? Or do I just have to set the field as a number with a default of 0 or something and generate/set them myself with JS?squallsama
04/14/2023, 4:05 AMawait Supabase.initialize(
url: <supabase_url>,
anonKey: <anon_key>,
headers: {
'Authorization': 'Bearer $userJwtToken',
});
But in order to make realtime work I have to pass userJwtToken
again -
var client = Supabase.instance.client;
client.realtime.setAuth(userJwtToken);
Is there any way how can I initialize Supabase with properly initialized realtime ? I saw doc in https://supabase.com/docs/guides/realtime/extensions/postgres-changes#custom-tokens but for flutter I'm not sure that it's a working solutionpanduram
04/14/2023, 4:39 AMbegin
insert into public.rooms (created_by_id, room_manager_id, room_name, room_key,starting_balance,room_open,player_id_list)
values (
cbi,
cbi,
rn,
rk,
sb,
true,
ARRAY[] :: uuid[]
);
UPDATE public.players
SET room_id_list = array_append(room_id_list, (SELECT id FROM public.rooms WHERE room_name = rn))
WHERE id = cbi;
end;
public.rooms table has this row level policy check : (auth.uid() = room_manager_id)
with role as authenticated
for INSERT
.
When i am calling this function from a nextjs api route function like this,
const cbi : string= session.user.id
const rn : string= req.body.room_name
const rk : string= req.body.room_key
const sb : number= req.body.starting_balance
let { data, error } = await supabase.rpc("create_room", {cbi, rn, rk, sb} );
if (error) console.error("rpc crete_room error : ",error);
else console.log("rpc create_room success : ",data);
This gives me an error ,
{
code: 'PGRST202',
details: 'Searched for the function public.create_room with parameter cbi or with a single unnamed json/jsonb parameter, but no matches were found in the schema cache.',
hint: null,
message: 'Could not find the function public.create_room(cbi) in the schema cache'
}
https://cdn.discordapp.com/attachments/1096293573193895946/1096293573374255155/image.png▾
jj_sessa
04/14/2023, 6:42 AMAMZ7860
04/14/2023, 7:18 AMdivrai
04/14/2023, 7:58 AMts
const { currentUser } = useAuth();
const [questionValue, setquestionValue] = useState("");
const [fileValue, setfileValue] = useState<File | null>(null);
const [subjectValue, setsubjectValue] = useState<string | null>(null);
const [moduleValue, setmoduleValue] = useState<string | null>(null);
const [marksValue, setmarksValue] = useState<number | "">(1);
const submitHandler = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
setLoading(true);
const file = fileValue;
const fileExt = file ? file.name.split(".").pop() : null;
const fileName = file ? `${Math.random()}.${fileExt}` : null;
const filePath = file ? `images/${fileName}` : null;
try {
if (!questionValue || !subjectValue || !moduleValue || !marksValue) {
throw new Error("Please fill all the fields");
}
const authorValue = userDetails?.id;
const orgNameValue = userDetails?.org_name;
const question = {
question: questionValue,
marks: marksValue,
module: moduleValue,
subject: subjectValue,
author: authorValue,
org_name: orgNameValue,
question_image: filePath,
};
const { error: uploadQuestionError } = await supabase
.from("questions")
.insert([question]);
if (uploadQuestionError) {
throw uploadQuestionError;
}
if (fileValue && filePath && file) {
const { data: fileUploadData, error: fileUploadError } =
await supabase.storage.from("question_image").upload(filePath, file);
console.log("file uploaded", fileUploadData);
if (fileUploadError) {
throw fileUploadError;
}
}
// success
} catch (error: any) {
// log
}
ibrahim-ml
04/14/2023, 8:35 AMriccardolardi
04/14/2023, 8:54 AMPROFILE STATUS ARCH CPUS MEMORY DISK RUNTIME ADDRESS
default Running aarch64 4 6GiB 60GiB docker
And latest supabase
and @supabase/supabase-js
Creation of new users via supabase.auth.admin.createUser()
or supabase.auth.signUp()
will result in following error:
AuthRetryableFetchError: fetch failed
at /Users/riccardolardi/Code/test-supabase-colima/node_modules/@supabase/gotrue-js/dist/main/lib/fetch.js:30:16
at Generator.next (<anonymous>)
at /Users/riccardolardi/Code/test-supabase-colima/node_modules/@supabase/gotrue-js/dist/main/lib/fetch.js:8:71
at new Promise (<anonymous>)
at __awaiter (/Users/riccardolardi/Code/test-supabase-colima/node_modules/@supabase/gotrue-js/dist/main/lib/fetch.js:4:12)
at handleError (/Users/riccardolardi/Code/test-supabase-colima/node_modules/@supabase/gotrue-js/dist/main/lib/fetch.js:27:40)
at /Users/riccardolardi/Code/test-supabase-colima/node_modules/@supabase/gotrue-js/dist/main/lib/fetch.js:87:35
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
__isAuthError: true,
status: 0
}
Anyone has an idea what could be happening?Dawnmist
04/14/2023, 9:59 AMsupabase.auth.mfa.enroll
. As I was debugging the page, I made some changes and then reloaded it. All subsequent attempts to load the enrollment page result in a null response to the supabase.auth.mfa.enroll
request.
If the user abandons their initial 2FA enrollment (e.g. closed tab, navigated elsewhere, etc), what is the application supposed to do to handle the situation when that same user attempts to enroll 2FA a second time?Kevin Tale
04/14/2023, 10:02 AMtypescript
import 'https://deno.land/x/xhr@0.3.0/mod.ts';
import { Configuration, OpenAIApi } from 'https://esm.sh/openai@3.2.1';
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
const configuration = new Configuration({
apiKey: Deno.env.get('OPENAI_API_KEY'),
});
const openai = new OpenAIApi(configuration);
serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders });
}
try {
const { query } = await req.json();
[...]
return new Response(JSON.stringify({ answer }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200,
});
} catch (error) {
return new Response(JSON.stringify({ error: error.message }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 400,
});
}
});
Here's the invocation on the frontend side :
typescript
async triggerEdgeFunction() {
const { data, error } = await supabaseClient.functions.invoke(
'my-edge-function',
{
body: {...},
}
);
}
And I got a CORS error on this call, and the OPTIONS is getting a 500 error.
Anyone got an idea?
Thanks for the help!matthieup
04/14/2023, 10:19 AMnyasinskiy
04/14/2023, 12:12 PMDwarfNinja
04/14/2023, 12:49 PM!inner
? And bonus question, does doing queries like this impact performance?
dart
getAllIdsOfFriends() async {
var friendIds = await supabase
.from('friends')
.select('friend')
.eq('user', supabase.auth.currentUser!.id);
final List<String> friendIdsList = friendIds.map<String>((obj) => obj['friend'] as String).toList();
return friendIdsList;
}
getAllPostsOfFriends() async {
List<String> friendIdsList = await getAllIdsOfFriends();
var data = await supabase
.from('timeline')
.select('*')
.in_('user', friendIdsList);
return data;
}
RubensNobre
04/14/2023, 1:35 PMfunkyj
04/14/2023, 1:46 PMNetail
04/14/2023, 1:47 PMfelarchondo
04/14/2023, 2:01 PMeyJOdnJHb25uYSI6Imd2VXVwIn0=
04/14/2023, 3:03 PMTimurKramar
04/14/2023, 3:27 PMusers
in my public schema owned by supabase_admin
. I started a project from the nextjs-subsription-payments, where by the end this table, and also some other, were created. I would now like to add columns to this table to store more info about users, but as it is owned by supabase_admin
, I don't have the rights to alter it in any way. I need a way to move the ownership to postgres
. Thanks for any tips.Rikka
04/14/2023, 3:33 PMdoot0
04/14/2023, 3:42 PMlocalhost:5173
I get a CORS rejection, despite me explicitly defining the given CORS headers in https://supabase.com/docs/guides/functions/cors.
I'm running supabase functions serve --debug
in order to serve my local functions and the Deno relay instance boots via docker successfully and listens on 0.0.0.0:8081
, but requests made to localhost:54321/functions/xyz
(my local supabase instance URL) claim that there is no Access-Control-Allow-Origin' header.
Any help or insight would be greatly appreciated. Cheersflimsycabbage
04/14/2023, 3:48 PMinvalid input syntax for type uuid:
when trying to upload to storage. I am using clerk for auth. Please help.Kevin Tale
04/14/2023, 3:52 PMtypescript
import { SMTPClient } from 'https://deno.land/x/denomailer@1.6.0/mod.ts';
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
const client = new SMTPClient({
connection: {
hostname: 'smtp.postmarkapp.com',
port: 2525,
auth: {
username: '...',
password: '...',
},
},
});
serve(async (req) => {
if (req.method === 'OPTIONS') {
return new Response('ok', {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'authorization, x-client-info, apikey, content-type',
},
});
}
try {
await client.send({
from: 'contact@my-domain.com',
to: 'someone@gmail.com',
subject: `the subject`,
content: `hello world!`,
});
} catch (error) {
return new Response(error.message, {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'authorization, x-client-info, apikey, content-type',
'Content-Type': 'application/json',
},
status: 500,
});
}
await client.close();
return new Response(
JSON.stringify({
done: true,
}),
{
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'authorization, x-client-info, apikey, content-type',
'Content-Type': 'application/json',
},
status: 200,
}
);
});
The error says on frontend in the headers is x-deno-error: {"code":"UNCAUGHT_EXCEPTION","message":"The deployment failed while serving the request."}
And the logs on the supabase dashboard says :
Error: invalid cmd
at SMTPConnection.assertCode (https://deno.land/x/denomailer@1.6.0/client/basic/connection.ts:55:19)
at SMTPConnection.writeCmdAndAssert (https://deno.land/x/denomailer@1.6.0/client/basic/connection.ts:98:14)
Does someone have an idea on why this is happening?
Thanks!Michael Ketzer | streamgeist.com
04/14/2023, 4:37 PMhttps://cdn.discordapp.com/attachments/1096474345276182548/1096474345657868369/Screenshot_2023-04-14_at_18.32.45.png▾
WalkerJson
04/14/2023, 5:04 PMhttps://cdn.discordapp.com/attachments/1096481060520468582/1096481060696621116/Timestamptz.gif▾
anggoran
04/14/2023, 6:05 PM