Kenneth J Hughes
02/17/2023, 5:26 AMimport { createClient } from '@supabase/supabase-js'
to fail with
Uncaught SyntaxError: The requested module './../../../../cross-fetch/dist/node-ponyfill.js' does not provide an export named 'default' (at PostgrestBuilder.ts:1:8)
in the browser console?Vince
02/17/2023, 5:46 AMconst {data, error} = await supabase.storage
.from("my-storage-bucket")
.remove([original_file_name]);
original_file_name
is the file name in a DB table that matches the file name in the storage bucket at root.
I think the syntax is correct but it can't get deleted. I'm don't have much familiarity with how RLS policies work and was hoping if someone could explain what I need to do to let each authenticated user to delete their own user-generated file that is uploaded in the storage bucket. I watched a YouTube video on it once but I can't seem to wrap my head around it.
I have a policy screenshot attached that handles the DELETE functionbkyerv
02/17/2023, 6:30 AMHo3einvb
02/17/2023, 7:14 AMGrimmjoww231
02/17/2023, 9:14 AMdev Joakim Pedersen
02/17/2023, 10:42 AM<input onChange={(e) => handleThumbnail(e)} type="file" accept="image/*;capture=camera" />
Here is the handleThumbnail function:
const handleThumbnail = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (!file) return;
try {
const insertedImage = await image(file, true)
setThumbnail(insertedImage)
} catch (error: any) {
setShowNotification(true)
setNotification(error.message)
}
};
The handleThumbnail function await image. which is a thing from a hook I made for this purpose.
I have one hook for images that will get their background removed and one for normal images. since it's happening several places in my app.
I will share the hook as a response to this post since I'm running out of characters. and also the function to delete an image belowEvostance
02/17/2023, 10:49 AMgame2023
02/17/2023, 12:32 PMavalanche
02/17/2023, 12:49 PMEidur
02/17/2023, 1:13 PMJacksGameDev
02/17/2023, 1:27 PMLukas V
02/17/2023, 1:37 PMcreated_by
column where I store uuid
that links to users
table.
Currently I have this function to get jobs and join 2 tables:
const getJobs = async () => {
let { data, error, count } = await supabase
.from('jobs')
.select(`*, created_by(*)`, { count: 'exact' });
if (error) {
throw new Error(`${error.message}: ${error.details}`);
}
return data;
};
Everything works, but what if I decided to lock users
table to protect some sensitive info. For that I created a view - public_users_info
, where I store fields like avatar_url, username, full_name.
However, it seems like I can't join this view as I would with the table? should I do something different?Martin INDIE MAKERS
02/17/2023, 1:39 PMtypescript
const channel: TYPEHERE = null
const req = supabase
.from('channel_users')
.select(`
id,
channel_id,
user_id (
id,
email,
first_name,
last_name
),
created_at
`)
.single()
channel = (await req).data
The query return the right type but in all my function i dont know how to get the type
so right now i do something like that, who feel very bad
typescript
interface ChannelUsers {
user_id: Database['public']['Tables']['users']['Row']
}
const element: Database['public']['Tables']['channel_users']['Row'] & ChannelUsers = {} as any
Then in my function i use
typeof element
to get the right type, but that seem a bit over engeneer.
Plus the type returned is too wide.Jim
02/17/2023, 1:46 PMjs
export async function getUserRole(userId: string, supabase: SupabaseClient) {
const { data, error } = await supabase
.from("user_roles")
.select("role")
.eq("id", userId);
if (error) {
throw error;
}
return data[0].role;
}
Probably better to not worry about it right?Hosenur
02/17/2023, 1:59 PMolivercito
02/17/2023, 2:38 PMgame2023
02/17/2023, 2:55 PMThomas H
02/17/2023, 3:23 PMsupabase start
? docker image save
is not the solution, save/load takes, combined, 6-7x times longer. Do anyone know of a different solution?ak4zh
02/17/2023, 3:25 PMjs
existing = supabase.table('tenders').select('id').match({"tender_no": item['tender_no'], "state_id": STATE_ID}).execute()
ERROR
File "/usr/local/lib/python3.11/site-packages/postgrest/_sync/request_builder.py", line 64, in execute
raise APIError(r.json()) from e
postgrest.exceptions.APIError: {'code': 'PGRST104', 'details': 'Failed to parse [("state_id","Filters.EQ.5"),("tender_no","Filters.EQ.125485")]', 'hint': None, 'message': 'Unexpected param or filter missing operator'}
Ken
02/17/2023, 3:47 PMJumpingBack
02/17/2023, 6:20 PMaction
and then set the headers from there but is this a viable option maybe? is this slow?cufta22
02/17/2023, 6:23 PMNeoPrint3D
02/17/2023, 7:22 PMavalanche
02/17/2023, 7:23 PMuser8923
02/17/2023, 7:32 PMyayza_
02/17/2023, 7:35 PMif "current time" (unix) - data.user.email_change_sent_at (converted to unix) < 86400 (24 hours), then show notice
, but if the new_email
or email_change_sent_at
key is removed automatically in supabase after a certain time anyway then I can just check if that exists.JoshTheNerd
02/17/2023, 8:05 PMjs
const test= await supabase.storage
.from("user-resumes")
.list("3d73b524-e959-470c-a6b3-b38e4e4d841a");
from the supabase JS SDK or if I try to create a signedURL it returns:
{ data: [], error: null }
if I use .list
{
data: null,
error: StorageApiError: The resource was not found
at C:\Users\joshu\Documents\projects\redacted\node_modules\@supabase\storage-js\dist\main\lib\fetch.js:20:20
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
__isStorageError: true,
status: 400
}
}
if I try to create a signedURLDYELbrah
02/17/2023, 8:19 PMimport { createBrowserSupabaseClient } from "@supabase/auth-helpers-nextjs";
import { useQuery } from "@tanstack/react-query";
import type { Database } from "../../../types/supabase-types";
const getCurrentUser = async () => {
const supabase = createBrowserSupabaseClient<Database>();
const {
data: { user },
error,
} = await supabase.auth.getUser();
if (error || !user) {
throw error;
}
return user;
};
const useUser = () =>
useQuery({
queryKey: ["activeUser"],
queryFn: getCurrentUser,
retry: false,
staleTime: 1000 * 60 * 20, // 20
refetchOnWindowFocus: false,
refetchOnMount: false,
});
export default useUser;
I noticed that if I want to use the useSupabaseClient() hook inside the getCurrentUser function (instead of createBrowserSupabaseClient), I can't do so because it can only be run inside a hook/component. I realize I could pass down the client through a parameter but that's not very clean.
Are there any issues with using createBrowserSupabaseClient instead? I like my current implementation and haven't ran into any issues yet.nateland
02/17/2023, 9:06 PMmisakss
02/17/2023, 10:03 PM