Ari
05/17/2023, 3:06 AMJoshTheNerd
05/17/2023, 5:08 AMJinni
05/17/2023, 5:13 AMWeykon
05/17/2023, 5:57 AMMrinal Wahal
05/17/2023, 6:21 AMMashwishi
05/17/2023, 7:41 AMjs
const Discord = require("discord.js");
const Supabase = require("supabase");
const intents = [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
];
const bot = new Discord.Client({ intents });
// Create a Supabase client
const supabase = new Supabase(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);
//....
i am trying to create a very simple discord.js powered bot and i am trying to connect it with supabase...
json
"dependencies": {
"discord.js": "^13.6.0",
"supabase": "^1.61.0"
},
this is the only thing i have installed like what i said a simple discord bot i just need to connect it.
Node version: v16.20.0
Error:
mashwishi@mac ****** % npm start
> ******@1.0.0 start
> node bot.js
node:internal/modules/cjs/loader:1029
throw err;
^
Error: Cannot find module 'supabase'
Require stack:
- /Users/mashwishi/Documents/******/bot.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1026:15)
at Function.Module._load (node:internal/modules/cjs/loader:871:27)
at Module.require (node:internal/modules/cjs/loader:1098:19)
at require (node:internal/modules/cjs/helpers:108:18)
at Object.<anonymous> (/Users/mashwishi/Documents/MechiDiscord/bot.js:2:18)
at Module._compile (node:internal/modules/cjs/loader:1196:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
at Module.load (node:internal/modules/cjs/loader:1074:32)
at Function.Module._load (node:internal/modules/cjs/loader:909:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/mashwishi/Documents/******/bot.js' ]
Crembo
05/17/2023, 7:54 AMselect * from table
?
https://cdn.discordapp.com/attachments/1108301577527251005/1108301577774698536/image.png▾
Waldemar
05/17/2023, 8:14 AMcontract.pdf
) to Order works fine via createSignedUploadUrl
, which doesn't need further authentication on client side or any RLS, from what I understood. All objects are saved in the root of the private bucket with random Names, which are then linked by various tables, such as Order.
Overall in our project, at first I tried to use RLS, which got quite complex and split our RBAC / business logic betweeen SQL and JS, so I moved everything to server-side JS. So I'd like to avoid or use only simple RLS for downloading files too.
To achieve that, as of now I'm thinking to also use signed URLs (createSignedUrls
), however, I wonder if I can at least access (download) the files without always making an extra call to createSignedUrls
every time I need to show fiels to the users.
So far the simplest way I found is to add this policy:
CREATE POLICY "Give authenticated users access to entire bucket" ON "storage"."objects" WITH CHECK ((bucket_id = 'my_protected_bucket'::text) AND (role() = 'authenticated'::text));
But I understand that it is bad security, since now any authenticated user can see (list) all files (objects) from the entire my_protected_bucket
...
There is no information on my users (i.e. metadata etc.) that links them directly to the files in Storage. The only link at the moment is (pseudocode):
user.email
-> order.client_email
-> order_files.order_id / order_files.storage_path
-> storage.objects
Any thoughts what else I can try?
Or do you think using createSignedUrls
best option for me after all and it's not that bad to call it all the time?
Thanks!Hollyqui
05/17/2023, 8:53 AMRares | Foton • Teeps
05/17/2023, 9:26 AMDECLARE
rarity numeric;
item_row RECORD;
item_cursor CURSOR FOR
SELECT *
FROM item_attributes
WHERE collection_id IS NOT NULL;
BEGIN
OPEN item_cursor;
LOOP
FETCH item_cursor INTO item_row;
EXIT WHEN NOT FOUND;
SELECT COUNT(*) * 100 / (
SELECT COUNT(*)
FROM item_attributes AS t3
WHERE t3.collection_id = item_row.collection_id
AND t3.collection_attribute_id = item_row.collection_attribute_id
) INTO rarity
FROM item_attributes AS t2
WHERE t2.collection_id = item_row.collection_id
AND t2.layer_value = item_row.layer_value
AND t2.collection_attribute_id = item_row.collection_attribute_id;
UPDATE item_attributes AS t1
SET trait_rarity = rarity
WHERE CURRENT OF item_cursor;
UPDATE items AS t1
SET average_trait_rarity = (
SELECT SUM(trait_rarity) / COUNT(trait_rarity)
FROM item_attributes AS t2
WHERE t2.item_id = t1.id
)
WHERE collection_id IS NOT NULL;
END LOOP;
CLOSE item_cursor;
RETURN NEW;
END
monks1975
05/17/2023, 9:45 AMNatoNathan
05/17/2023, 10:01 AMsupabase functions serve --no-verify-jwt --env-file .env --import-map ./supabase/functions/import_map.json --debug
sh
serving the request with /home/deno/functions/webhook-voice-answer
DEBUG Opening cache /root/.cache/deno/dep_analysis_cache_v1...
DEBUG FileFetcher::fetch() - specifier: file:///home/deno/_shared/home/deno/functions/webhook-voice-answer/index.ts
worker thread panicked No such file or directory (os error 2)
Error: channel closed
at async UserWorker.fetch (ext:sb_user_workers/user_workers.js:50:21)
at async Server.<anonymous> (file:///home/deno/main/index.ts:102:16)
at async Server.#respond (https://deno.land/std@0.182.0/http/server.ts:220:24)
DEBUG max duration reached for the worker. terminating the worker. (duration 1m0s)
failed to send the halt execution signal
failed to send the halt execution signal
Here is the function at functions/webhook-voice-answer/index.ts
ts
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts';
console.log('Hello from Functions!');
serve(async (req) => {
const { name } = await req.json();
const data = {
message: `Hello ${name}!`,
};
return new Response(
JSON.stringify(data),
{ headers: { 'Content-Type': 'application/json' } },
);
});
it happens to all functionsTheRien
05/17/2023, 11:41 AMpublic.profiles
table as suggested by Supabase: https://supabase.com/docs/guides/auth/managing-user-data
Now I can get the authenticated user by doing supabase.auth.getUser()
, but that doesn't give me the associated profile. My policies are such that users can view other profiles as well, so doing supabase.from('profiles').select()
does't work either. Of course I can combine the two as such:
const uid = (await supabase.auth.getUser()).data.user.id;
const profile = await supabase.from('profiles').select().eq('id', uid);
But that requires two API-calls and I'd logically prefer one. Is there any way of doing that? My preference would be something like supabase.auth.getUser('profiles(name)')
, like providing relations in the selection of getUser
akub
05/17/2023, 12:12 PMsend_http_request('SOME_URL', 'POST', 'null', 'API_ROUTE_SECRET', '1000');
SOME_URL and API_ROUTE_SECRET is taken from envs table inside, and the function is just a copy of supabase functions http_request.
The issue is that if i have a trigger that runs this function, the whole database freezes and doesn't send back anything anywhere.
It throws internal server error on getting current user and Database client error on insert where the trigger should run the function. Am i missing something? The whole database breaks, it is unusable.
https://cdn.discordapp.com/attachments/1108366333227302943/1108366333613187194/image.png▾
https://cdn.discordapp.com/attachments/1108366333227302943/1108366334401728552/image.png▾
Muphet
05/17/2023, 12:15 PMYANN
05/17/2023, 12:41 PMmdc405
05/17/2023, 1:00 PMsupabase network-restrictions --project-ref {ref} get --experimental
I'm ultimately doing this to try to unban my IP - as I tried several times to access my db with the wrong password and now I think my IP is banned?enti
05/17/2023, 1:04 PMAdam Ambrosius
05/17/2023, 2:23 PMUser Id=postgres;Password={passowrd};Server={supabase_server};Port=6543;Database=postgres;Pooling=true",
What else do I need to do to use this with serverless functions? I thought these changes were going to dop the connections after each transactionzeedee
05/17/2023, 2:32 PMjson
{
"session": {
"expires_at": 1684337083,
"expires_in": 3539,
"token_type": "bearer",
"access_token": "askdjhflaksdjf",
"refresh_token": "eM20FtuQtXgYTlKAx5DxgQ",
"provider_token": null,
"provider_refresh_token": null,
"user": {
"id": "al;sdkfjasdlfkjadsf",
"aud": "authenticated",
"email": "zach@email.ca",
"phone": "",
"app_metadata": {
"provider": "email",
"providers": [
"email"
]
},
"user_metadata": {},
"role": "authenticated",
"aal": "aal1",
"amr": [
{
"method": "password",
"timestamp": 1684271098
}
],
"session_id": "5040ae41-87a3-4ae9-9002-3e59b1003f16"
}
},
"data": []
}
when I change the role permissions to anon, then I get
json
//everything else +
"data": [
{
"id": 1,
"scheduled_at": "2023-05-16T20:45:47.575814+00:00",
"date_picked_up": null,
"date_delivered": null,
"date_billed": null,
"price_per_tonne": 12,
"price_per_flat_rate": null,
"min_tonnage": 44,
"pickup_destination_id": 1,
"delivery_destination_id": 2,
"status": "ordered",
"active": true,
"order_document_url": null,
"delivery_document_url": null,
"tonnage": null
}
]
i'm curious, because the system says the user is authenticated
https://cdn.discordapp.com/attachments/1108401551791366196/1108401552030445588/image.png▾
TheRien
05/17/2023, 2:36 PMRyan the Temp
05/17/2023, 3:12 PMdocker -v
I get Docker version 23.0.5, build bc4487a
I'm on osxformigueiro
05/17/2023, 3:20 PMholabruno
05/17/2023, 3:33 PMSelf
05/17/2023, 3:53 PMError inserting data: {
code: '42501',
details: null,
hint: null,
message: 'new row violates row-level security policy for table "xx"'
}
When I switch to the same policy with 'Anon' then it works. It seems the supabase client does not send out the authenticated role/access token ?
I have a js file running with node, and I can sign up with email
js
const { data:auth, error } = await supabase.auth.signUp({
email: 'example@email.com',
password: 'example-password',
})
console.log('Signed in successfully:', auth);
This returns the following, indicating that the user technically is authenticated ?
Signed in successfully: {
session: {
access_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.....',
token_type: 'bearer',
expires_in: 3600,
refresh_token: 'CP2UbNwqZ2-...',
user: {
id: 'xxx',
aud: 'authenticated',
role: 'authenticated',
email: 'mail@example.org',
email_confirmed_at: '2023-05-17T11:35:16.782073Z',
phone: '',
confirmed_at: '2023-05-17T11:35:16.782073Z',
last_sign_in_at: '2023-05-17T15:49:20.571863874Z',
app_metadata: [Object],
user_metadata: {},
identities: [Array],
created_at: '2023-05-17T11:35:16.7739Z',
updated_at: '2023-05-17T15:49:20.573549Z'
},
expires_at: 1684342161
},
user: {
id: 'xxxx',
aud: 'authenticated',
role: 'authenticated',
email: 'mail@example.org',
email_confirmed_at: '2023-05-17T11:35:16.782073Z',
phone: '',
confirmed_at: '2023-05-17T11:35:16.782073Z',
last_sign_in_at: '2023-05-17T15:49:20.571863874Z',
app_metadata: { provider: 'email', providers: [Array] },
user_metadata: {},
identities: [ [Object] ],
created_at: '2023-05-17T11:35:16.7739Z',
updated_at: '2023-05-17T15:49:20.573549Z'
}
}
The user returns null
js
const { data: { user } } = await supabase.auth.getUser()
// returns null
console.log(user)
Is the user signing in incorrectly or why is the authentification token only using the anon user and not the authenticated user ?kekington
05/17/2023, 3:58 PMconfirmation_token
from the users
table but it seems to be hashed.SunTzu
05/17/2023, 4:16 PMid email username message_count
1. test@test.com thisuser 123
CalculusAce
05/17/2023, 5:17 PMven
05/17/2023, 6:02 PMtommycox
05/17/2023, 7:18 PM