wasinwatt
12/30/2022, 5:53 PMLukas V
12/30/2022, 6:18 PMbegin
insert into public.users (id, full_name, avatar_url, email)
values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url', new.raw_user_meta_data->>'email');
return new;
end;
Everything works except email which is not added to the users table, what is the reason for it, is there a different way I should be extracting email?Edan
12/30/2022, 6:57 PMBadBadJellyBean
12/30/2022, 7:06 PMMichael Maust
12/30/2022, 7:29 PMleviwhalen
12/30/2022, 8:21 PMjsonb
field is typed as Json
-- but I would like to define it using another type in my application. Is there a way to pass that type in a similar way to injecting the Database
type during client initialization?
Thanks!kevinwasie
12/30/2022, 8:40 PMintheclouddan
12/30/2022, 8:43 PMany
for the Schema? I'm not sure what I'm doing wrong with itDDupasquier
12/30/2022, 9:05 PMjs
const getMyStories = async () => {
if (profileId) {
const { data, error } = await supabase
.from('stories')
.select(
'id, title, author, updatedAt, profileId (id, username, avatarUrl), pages: pages (id, background, screenshot)'
)
.eq('profileId', profileId)
.order('updatedAt', { ascending: false });
if (error) {
throw new Error(error.message);
}
stories = data;
}
};
onMount(() => {
supabase.auth.getSession().then(({ data }) => {
session = data.session;
});
supabase.auth.onAuthStateChange((_event, _session) => {
session = _session;
});
});
afterUpdate(() => {
getMyStories();
});
So basically I'm getting my session onMount. Once the component is mounted I go ahead and get my thumbnails based on information I received from the session.
Assets in storage reflect my changes.
Client does not.
Is this a svelte thing?
Thanks in advance for any advice!typeleven
12/30/2022, 9:48 PMDDupasquier
12/30/2022, 10:06 PMjs
const getMyStories = async () => {
if (profileId) {
const { data, error } = await supabase
.from('stories')
.select(
'id, title, author, updatedAt, profileId (id, username, avatarUrl), pages: pages (id, background, screenshot)'
)
.eq('profileId', profileId)
.order('updatedAt', { ascending: false });
if (error) {
throw new Error(error.message);
}
stories = data;
}
};
onMount(() => {
supabase.auth.getSession().then(({ data }) => {
session = data.session;
});
supabase.auth.onAuthStateChange((_event, _session) => {
session = _session;
});
});
afterUpdate(() => {
getMyStories();
});
js
export const getPageThumbnail = async () => {
if (story?.pages[0].screenshot) {
const { data: url } = supabase.storage
.from('page-screenshots')
.getPublicUrl(story.pages[0].screenshot);
return url;
}
};
let background: { publicUrl: string } | undefined;
$: url = background?.publicUrl;
afterUpdate(() => {
setTimeout(async () => {
background = await getPageThumbnail();
}, 10);
});
So basically I'm getting my session onMount. Once the component is mounted I go ahead and get my thumbnails based on information I received from the session.
Assets in storage reflect my changes.
Client does not.
Is this a svelte thing?
Thanks in advance for any advice!AmusedGrape
12/30/2022, 10:14 PMnew row violates row-level security policy for table "listItems"
when using .select(*)
after a .insert()
. Inserting works fine, so selecting is the issue.
My select RLS code: can_view_list(( SELECT profiles.id FROM profiles WHERE (profiles."user" = uid())), list)
Function code:
sql
create or replace function can_view_list(user_id uuid, list_id uuid)
returns bool
language plpgsql
as
$$
BEGIN
IF (SELECT "sharingStatus" FROM lists WHERE id = list_id) = 'invite' THEN
return exists (SELECT * FROM "listUsers" WHERE "user" = user_id);
ELSE
return true;
END IF;
END $$;
I'm not entirely sure what the issue is; Running select can_view_list('...', '...')
(ids omitted), it works fine.
Any ideas?Martacus
12/30/2022, 10:53 PMharryc
12/30/2022, 11:02 PMDomain Controller
12/30/2022, 11:17 PMDDupasquier
12/30/2022, 11:19 PMjs
import { supabase } from '$lib/supabase';
export async function load({ params }: { params: { page_id: number } }) {
const { data: page, error } = await supabase
.from('pages')
.select(
'id, pageNumber, background, elements: elements (id, elementName, x, y, zIndex, size, type, color, text, pageId)'
)
.eq('id', params.page_id);
if (error) {
throw new Error(error.message);
}
return {
page
};
}
The page then consumes the data and passes it to a canvas element:
js
<script lang="ts">
import Canvas from '$lib/components/canvas/Canvas.svelte';
export let data: EditPageProps;
</script>
<Canvas info={data.page[0]} />
The canvas element then takes that data as props and provides the element data to an ImgElement component:
js
<script lang="ts">
import { supabase } from '$lib/supabase';
import { onMount } from 'svelte';
import { page } from '$app/stores';
import { screenshotCanvas } from '$lib/utils';
import ImgElement from '$lib/components/canvas/ImgElement.svelte';
import { uploadThumbnail, saveBgColor } from '$lib/services/pageActions';
import ColorPicker from '../ColorPicker.svelte';
export let info: {
id: number;
pageNumber: number;
background: string;
elements: PageElement[];
};
$: background = '';
const setColor = (color: string) => {
background = color;
};
onMount(async () => {
background = info.background;
supabase
.channel('public:elements')
.on('postgres_changes', { event: 'INSERT', schema: 'public' }, (payload) => {
info.elements = [...info.elements, payload.new] as PageElement[];
})
.subscribe();
supabase
.channel('public:elements')
.on('postgres_changes', { event: 'DELETE', schema: 'public' }, (payload) => {
info.elements = info.elements.filter((element) => element.id !== payload.old.id);
})
.subscribe();
});
const doScreenshot = async () => {
const file = await screenshotCanvas('#canvas');
file && uploadThumbnail(file, $page.params.page_id);
};
</script>
{#if info.background}
<div id="canvas" style="background: {background}">
{#if info.elements}
{#each info.elements as element}
<ImgElement {element} />
{/each}
{/if}
<div class="page">
Page {info.pageNumber}
</div>
</div>
{/if}
<div class="controls">
<ColorPicker color={background} {setColor} />
<button
class="save"
on:click={() => {
doScreenshot();
saveBgColor(info.id, background);
}}
>
Save
</button>
</div>
logemann
12/31/2022, 12:06 AMdraco
12/31/2022, 12:25 AMBrian
12/31/2022, 12:44 AMupsert
, my code feels very verbose. After using useMutation
and handling all of the onError
and onSuccess
responses for the first insert then doing it all again for the the relational insert, it's a lot. Then, add in some code to check if it's an update or new insert and things are getting pretty hard to read.
Anyone have some production code examples where they're mutating multiple relational tables and feel their code is succinct?Kai NABETA
12/31/2022, 3:05 AMsupabase start
, it does not start up and I get the following error Do you know of any solutions?
Error: failed to connect to `host=localhost user=postgres database=postgres`: dial error (timeout: dial tcp 127.0.0.1:54322: i/o timeout)
Try rerunning the command with --debug to troubleshoot the error.
49Ryann
12/31/2022, 3:24 AMFunctionsHttpError: Edge Function returned a non-2xx status code
{
name: 'FunctionsHttpError',
context: Response {
type: 'cors',
url: 'https://xoehwyftrgxzpwtgsesp.functions.supabase.co/verify-mobile',
redirected: false,
status: 400,
ok: false,
statusText: '',
headers: Headers {},
body: ReadableStream { locked: false },
bodyUsed: false
},
stack: 'FunctionsHttpError: Edge Function returned a non-2xx status code\n' +
' at FunctionsClient.<anonymous> (http://localhost:4200/vendor.js:5579:17)\n' +
' at Generator.next (<anonymous>)\n' +
' at fulfilled (http://localhost:4200/vendor.js:5493:24)\n' +
' at _ZoneDelegate.invoke (http://localhost:4200/polyfills.js:10072:158)\n' +
' at Object.onInvoke (http://localhost:4200/vendor.js:114063:25)\n' +
' at _ZoneDelegate.invoke (http://localhost:4200/polyfills.js:10072:46)\n' +
' at Zone.run (http://localhost:4200/polyfills.js:9855:35)\n' +
' at http://localhost:4200/polyfills.js:10948:28\n' +
' at _ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:10099:171)\n' +
' at http://localhost:4200/vendor.js:113743:49',
message: 'Edge Function returned a non-2xx status code'
}
Heres how it's sent back from the edge function:
return new Response(JSON.stringify({ error: 'Mobile number is not valid.' }), { headers: { ...corsHeaders, 'Content-Type': 'application/json' }, status: 400 })
any ideas?
I can easily write an error on the frontend as it's a specific function I'm calling but I'd prefer getting feedback from the server.56e5
12/31/2022, 4:09 AMserial
(i.e. int
) to uuid
and now I get a type-related error back from the API because the ID I'm passing is not an integer:
> 22P02: invalid input syntax for type integer: "40dfbd05-9126-4a36-81a8-211cf8f28d1c"
I've checked the DB (both through a PG client and the Supabase admin UI) and the column type has been updated to UUID fine.
Is there some way to flush the API schema? Maybe it's a Cloudflare caching thing?
Thanks!Mr_Incredible442
12/31/2022, 8:08 AMizurugi
12/31/2022, 8:26 AMFlorian
12/31/2022, 11:07 AMevro.eth 🇵🇷
12/31/2022, 3:11 PMzilchg00d
12/31/2022, 3:40 PMRazil
12/31/2022, 5:24 PMsupabase start
it will redownload the docker images (if you previously died a supabase stop
) it needs, can this behavior be changed? Not sure why it's deleting the once-downloaded images.C o m f i i
12/31/2022, 5:36 PMdata
, and a data_updated_at
timestamp column which updates only when data
is updatedvikramark
12/31/2022, 5:53 PM