nickbryant.fyi
05/20/2023, 5:25 PM-- Function to check if the user is the creator of the organization
CREATE OR REPLACE FUNCTION public.has_created_org(
user_id UUID,
organization_id UUID
)
RETURNS BOOLEAN AS
$$
DECLARE
user_is_creator BOOLEAN;
v_user_id UUID := user_id;
v_organization_id UUID := organization_id;
BEGIN
SELECT COUNT(*) > 0
INTO user_is_creator
FROM public.organizations AS orgs
WHERE orgs.id = v_organization_id AND orgs.created_user_id = v_user_id;
RETURN user_is_creator;
END;
$$
LANGUAGE plpgsql;
Policy:
CREATE POLICY "organization_roles_policy_org_level" ON "public"."organization_roles"
FOR INSERT
WITH CHECK ((has_created_org(auth.uid(), organization_id));
The only other policies i have for the table organization_roles are for update/delete and select. they are different.
I had my user successfully create an organization and i tested has_create_org via CLI and ensured that indeed organization_roles.organization_id
and the user's auth.id
do return TRUE from this function.
This is the code im invoking:
await client.from('organization_roles').insert({
organization_id: newOrg.id,
user_id: currentUser.id,
role: 'OWNER',
})
And this is the result:```
"new row violates row-level security policy for table \"organization_roles\""```
I've been working on this for hours so any help would be very appreciated. I just want better ways to debug these policies and stuff.cyberpunq
05/20/2023, 5:40 PMFailed to create trigger: failed to create pg.triggers: zero-length delimited identifier at or near """"
See relevant screenshot.
https://cdn.discordapp.com/attachments/1109536261682766017/1109536261909266462/pgtrigger.png▾
Will_Buyers
05/20/2023, 6:27 PMzerosodium
05/20/2023, 6:44 PMjs
const { data, error } = await supabase
.from("restaurants")
.select(
`
*,
reservations (
*,
bids (
*
)
)
`
)
.eq("venue_id", venue_id);
osamita
05/20/2023, 7:10 PMcolumn_one=eq.value,column_two=eq.other_value
,
},
() => {
alert('row inserted');
}
)
.subscribe()
but the event does not execute the function with two filter, only with just one.
is there a way to subscribe to a channel using more than one filter?cyberpunq
05/20/2023, 7:54 PMnew
object. How does one get the user_id
of the user who triggered the trigger that called this function? Help would be appreciated!
This is my script:
begin
insert into public.members(user_id, organization_id, is_admin)
values(???, new.id, true)
end;
nicolasstrands
05/20/2023, 8:20 PMhyper::Error(User(Service), operation was canceled: connection was not ready
Caused by:
connection was not ready)
Anyone knows where I should be looking to solve this by any chance?Hugos
05/20/2023, 9:12 PMts
const channel = supabase
.channel('incoming-messages')
.on(
'postgres_changes',
{ event: 'INSERT', schema: 'public', table: 'messages', filter: `room_id=eq.${room.id}` },
(payload: Message) => {
console.log(payload);
messages.push(payload);
}
)
.subscribe();
peter-lustig
05/20/2023, 9:17 PMheypex
05/20/2023, 9:24 PMHugos
05/20/2023, 10:04 PMjs
await supabase
.from('messages')
.select(`
*,
auth.users (
profiles (username)
)
`);
But this does not work.Ben-jam-in
05/20/2023, 10:51 PMInfraction
05/20/2023, 11:15 PMPanda
05/21/2023, 6:39 AM-- 1. Allow a user to access their own files
create policy "Individual user Access"
on storage.objects for select
using ( auth.uid() = owner );
Would applying a policy this way be applied to all storages? Should I specify the bucket_id
if I want it applied to a specific bucket?EKI
05/21/2023, 7:11 AMpjs
05/21/2023, 7:29 AMkenrhee
05/21/2023, 7:54 AMPhilipp_Nut
05/21/2023, 8:05 AMzwarag
05/21/2023, 10:13 AMdart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:spacevault_cash/constants.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:supabase/supabase.dart' as supabase_;
import '../services/supabase_service.dart';
class TestPage extends ConsumerWidget {
const TestPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context, WidgetRef ref) {
final user = ref.watch(userProvider);
print(supabase.auth.currentSession);
// Use the user variable here
return ElevatedButton(
onPressed: () {
ref.read(supabaseProvider).auth.signInWithOAuth(
supabase_.Provider.github,
redirectTo: kIsWeb ? null : authRedirectUrl);
},
child: Text(user != null ? 'Logged in' : 'Login'),
);
}
}
I'm having trouble authenticating users when using the web client. When clicking on the button, the user gets redirected to github. After entering valid credentials, the users gets sent back to the application, however supabase.auth.currentSession
prints null
.
However, I can see the access_token in the url bar, so it should actually have everything it needs. Any Ideas?
Just for context: This works fine for iOS and Androidstatuscode200
05/21/2023, 10:15 AMWaldemar
05/21/2023, 10:58 AMpg
)
2) Extend it with some access control rules (RBAC) for checking on the server-side code (e.g. which user role can insert/update which tables and columns)
We tried Postgresql RLS, but it doesn't work for us
I looked into generic tools that can generate JSON from Postgresql schema, such as:
https://github.com/tjwebb/pg-json-schema-export
https://www.pg-structure.com/
...but didn't manage to make them work and they seem too complicated for once-off use.
Also I know there is
https://supabase.com/docs/guides/api/rest/generating-types
...but it generates TypeScript, which I understand won't give me the 1) and 2) above.
Then there are tools like Prisma, but again, I don't think I can do 2) wit it and it is a full blown ORM and also an overkill for what I need anyway.
Can you recommend other ways / tools how I can do it?
I imagine something like:
{
tables: [
{
name: orders,
columns: [
{
name: 'id',
type: 'TEXT'
}
],
constraints: [
...
]
}
]
}
Thanks!FirePuffin
05/21/2023, 11:09 AMhttps://cdn.discordapp.com/attachments/1109800047186558996/1109800047643721808/image.png▾
Hugos
05/21/2023, 12:16 PMLorenium
05/21/2023, 1:47 PMericrav
05/21/2023, 2:02 PM1.62.3
and when I visit the Storage page in my local Studio it displays "Internal Server Error" and I can't create buckets.
Looking at the logs in docker, I see:
DBError: new row violates row-level security policy
at DBError.fromDBError (/app/dist/storage/database/knex.js:416:16)
at Function.<anonymous> (/app/dist/storage/database/knex.js:351:31)
at Function.emit (node:events:513:28)
at Function.emit (node:domain:489:12)
at Client_PG.<anonymous> (/app/node_modules/knex/lib/knex-builder/make-knex.js:299:10)
at Client_PG.emit (node:events:525:35)
at Client_PG.emit (node:domain:489:12)
at /app/node_modules/knex/lib/execution/internal/query-executioner.js:46:12
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Runner.ensureConnection (/app/node_modules/knex/lib/execution/runner.js:300:14) {
statusCode: 403,
error: 'Unauthorized',
originalError: error:
SELECT
set_config('role', $1, true),
set_config('request.jwt.claim.role', $2, true),
set_config('request.jwt', $3, true),
set_config('request.jwt.claim.sub', $4, true),
set_config('request.jwt.claims', $5, true),
set_config('request.headers', $6, true),
set_config('request.method', $7, true),
set_config('request.path', $8, true);
- permission denied to set role "service_role"
at Parser.parseErrorMessage (/app/node_modules/pg-protocol/dist/parser.js:287:98)
Torwent
05/21/2023, 2:03 PMtypescript
const { data, error } = await supabase.auth.signInWithPassword({
email: SERVICE_USER,
password: SERVICE_PASS
})
if (error) {
console.error(error)
return fail(500, { form })
}
console.log(data) //prints the logged in user information correctly
console.log((await supabase.auth.getUser()).data) //prints { user: null }
Naturally, since the current user is null anything I try to do will work as if I wasn't logged in.
@supabase/supabase-js 2.22.0
Can anyone tell me if it's something I'm doing wrong? because this is driving me insane!Moeed
05/21/2023, 2:04 PMtererun / てれるん
05/21/2023, 2:32 PMts
import './globals.css'
import SupabaseProvider from './supabase-provider'
export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<SupabaseProvider session={session}> { /* <- here */ }
<SupabaseListener serverAccessToken={session?.access_token} />
{children}
</SupabaseProvider>
</body>
</html>
)
}
Thank you!Motz
05/21/2023, 3:26 PM