anderjaska
08/31/2022, 3:59 PMflorian_engl
08/31/2022, 5:04 PMJulien
08/31/2022, 5:57 PMQiushi
08/31/2022, 6:06 PMsrc
attribute, but it loads all the html content in a pre
tag, so it ends up showing the code again.
Is there a option to let storage sends back the raw html code?jxyz
08/31/2022, 6:38 PMsql
CREATE TYPE "role" as enum ('administrator', 'moderator');
CREATE TYPE "scope" as enum ('authentication', 'authorization');
CREATE TYPE "action" as enum ('read', 'write');
CREATE TABLE "roles" (
"id" bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
"name" role NOT NULL
);
CREATE TABLE "permissions" (
"id" bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
"role_id" bigint REFERENCES "roles" ON DELETE CASCADE NOT NULL,
"scope" scope NOT NULL,
"actions" action[] NOT NULL
);
CREATE TABLE "user_roles" (
"id" bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
"user_id" uuid REFERENCES auth.users ON DELETE CASCADE NOT NULL,
"role_id" bigint REFERENCES "roles" ON DELETE CASCADE NOT NULL
);
ALTER TABLE "roles" ENABLE ROW LEVEL SECURITY;
ALTER TABLE "permissions" ENABLE ROW LEVEL SECURITY;
ALTER TABLE "user_roles" ENABLE ROW LEVEL SECURITY;
-- let users see their roles based on their user_roles
-- [ ] OK
CREATE POLICY "roles: select" ON "roles" AS PERMISSIVE
FOR SELECT TO authenticated USING (
EXISTS (
SELECT 1 FROM "user_roles" as user_role
WHERE user_role.role_id = "id"
AND user_role.user_id = auth.uid()
)
);
-- let users see their permissions based on their user_roles
-- [x] OK
CREATE POLICY "permissions: select" ON "permissions" AS PERMISSIVE
FOR SELECT To authenticated USING (
EXISTS (
SELECT 1 FROM "roles" as role
WHERE role.id = "role_id"
AND EXISTS (
SELECT 1 FROM "user_roles" as user_role
WHERE user_role.role_id = role.id
AND user_role.user_id = auth.uid()
)
)
);
-- let users see their user_roles
-- [x] OK
CREATE POLICY "user_roles: select" ON "user_roles" AS PERMISSIVE
FOR SELECT To authenticated USING (
"user_id" = auth.uid()
);
hard2kill
08/31/2022, 11:48 PMError: Invalid project ref format. Must be like `abcdefghijklmnopqrst`.
. How can I fix that?luke90275
09/01/2022, 6:25 AMwhiskeywizard
09/01/2022, 7:20 AMkresimirgalic
09/01/2022, 7:59 AMSatou kuzuma
09/01/2022, 8:35 AMGuru
09/01/2022, 3:16 PMLEGEND
09/01/2022, 4:16 PMstha_ashesh
09/01/2022, 4:45 PMSQL
SELECT *
FROM "movie_database"
WHERE "movie_database"."mov_id" IN (
SELECT "genre".mov_id
FROM "genre"
where "genre".genre_val=[some_value]
)
---
I have two tables - movie_database
table and genre
table. movie_database
table has mov_id
primary key. genre
table has mov_id
(foreign key referring to movie_database) and genre_val
.
Right now I am doing
xyz.supabase.co/rest/v1/genre?genre_val=eq.[some_value]&select=movie_database(*)
It would seem okay but I feel like it is joining rather than just pure filtering. Because when we do just filter without foreign key, I get
[
{movie_database item 1},
{movie_database item 2}
]
But right now I am getting following structure.
[
{
"movie_database": {movie_database item 1},
},
{
"movie_database": {movie_database item 1},
},
]
arch
09/02/2022, 5:32 AMํ์ฐHyeon
09/02/2022, 5:43 AMjaitaiwan
09/02/2022, 6:42 AMCREATE OR REPLACE TRIGGER
there's a syntax error for TRIGGER
but if I remove OR REPLACE
then it works perfectly.
According to SELECT version()
I'm using postgres 14 so I don't understand why it's not working.
Supabase Cloudslurp
09/02/2022, 7:06 AMDevThoughts
09/02/2022, 8:46 AMCANDY
09/02/2022, 8:51 AMboeledi
09/02/2022, 9:10 AMimport { serve } from "https://deno.land/std@0.131.0/http/server.ts";
import fetch from "../../../node_modules/node-fetch";
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" } },
)
})
Many thanks for your helpbent
09/02/2022, 10:20 AMts
.or(`discord.eq.${user.username}#${user.discriminator}, discord_id.eq.${user.id}`)
that I'd like to replace with .user(user)
. I think I'm looking for extension methods / blanket implementations, but I'm struggling to pull it off.
I was able to do this simpler one
ts
declare global {
interface Array<T> {
pickAny(): T;
}
}
Array.prototype.pickAny = function <T,>() { return (this as Array<T>)[Math.floor(Math.random() * (this as Array<T>).length)] }
export { }
but this principle doesn't seem to work with `PostgrestFilterBuilder`s.
basically I want to do stuff like this
https://diesel.rs/guides/composing-applications.htmlLukas V
09/02/2022, 1:13 PMKey
Here is my code:
Is this how it's supposed to be done? What happens if one of the api calls fail? How would I handle these errors?
const onSubmit: SubmitHandler<Inputs> = async (data) => {
try {
if (file && user?.id) {
new Compressor(file, {
quality: 0.8,
height: 1350,
width: 1080,
resize: 'cover',
convertTypes: 'image/png', // here it converts to jpg after size exceeds 50kb
convertSize: 50000,
async success(result) {
const { data: postsData } = await supabase
.from('posts')
.insert({
caption: data.caption,
created_by: user.id,
image_url: 'placeholder'
});
const { data: imageData } = await supabase.storage
.from('user-content')
.upload(`${user.id}/posts/${postsData?.[0].id}.jpeg`, result, {
contentType: 'image/jpeg'
});
await supabase
.from('posts')
.update({
image_url: `https://smldlcomasdasdddnjg.supabase.co/storage/v1/object/public/${imageData?.Key}`
})
.eq('id', postsData?.[0].id);
}
});
}
} catch (error) {
console.log(error);
}
};
gaIaxy
09/02/2022, 2:34 PMJulien
09/02/2022, 2:37 PMEmbm
09/02/2022, 2:37 PMjson_build_object(...)
as it looks like it's not parsing the inner contents of the query and simply outputs a basic Record
type:
ts
some_postgres_function: {
Args: Record<PropertyKey, never>;
Returns: Json;
};
Is there any way to generate more precise types or do I need to manually define some interface/type and make sure to keep it in sync with the function's content?gbb
09/02/2022, 2:46 PMcreate or replace function public.handle_new_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
insert into public.profiles (id, email)
values (new.id, new.email);
return new;
end;
$$;
-- trigger the function every time a user is created
drop trigger if exists on_auth_user_created on auth.user;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
Example auth:
const { user, session, error } = await supabase.auth.signUp(
{
email: 'example@email.com',
password: 'example-password',
},
{
data: {
first_name: 'John',
age: 27,
},
}
)
ymahmo
09/02/2022, 3:20 PMlet { data, error: uploadError } = await supabase.storage
.from("snapshots")
.upload(response.name, response);
> Upload Error: [TypeError: Network request failed]Kylar
09/02/2022, 5:15 PMerror: {
message: 'An invalid response was received from the upstream server',
status: 502
}
Any ideas on how to debug what is going on?try_catch.js
09/02/2022, 6:59 PMhttp://localhost:3000/user/asd
,
}
)`
Then I click on my email the 'magic link', and then
When my protected page pages/user/[id].js
attempts to get the already authenticated user with this
export const getServerSideProps = withPageAuth({
redirectTo: '/auth/sign_in_or_create_account',
async getServerSideProps(ctx) {
const { user } = await getUser(ctx)
return { props: { user: user } }
},
})
I'm redirected back to login page when I should stay at /user/[id]
route.
How does the server side page can 'know' that the user already clicked the magic link from the email?nahtnam
09/02/2022, 8:24 PMreturn supabaseAdminClient.from("feeds").select("*,sources!inner(*)").eq("enabled", true)
The type is { ... feed stuff here } & { sources: unknown }
so it looks like it recognizes the join but its not filling in the type.