Revaycolizer
05/08/2023, 5:20 PMimport
statements or require
calls are correct. Below is the code import Uppy from '@uppy/core'
import XHRUpload from '@uppy/xhr-upload'
import ProgressBar from '@uppy/progress-bar'
import '@uppy/core/dist/style.min.css';
import '@uppy/progress-bar/dist/style.min.css';
const uppy = new Uppy()
uppy.use(XHRUpload, { endpoint: 'https://api.supabase.io/storage/v1/object/public/files' })
uppy.use(ProgressBar, {
target: '#progress-bar-container',
hideAfterFinish: false
})
const handlePost = useCallback(async () => {
if (user) {
try {
const { successful } = await uppy.upload()
if (successful) {
const file = uppy.getFile('0')
if (file && file.progress && file.progress.uploadComplete && file.response && file.response.uploadURL) {
const { data, error } = await supabase.from('category').insert({
vname: vname,
selectedValue: selectedValue.category,
user: user,
file_url: file.response.uploadURL
})
if (data && vname && successful) {
toast.success('Post uploaded successfully')
setOpen(false)
location.reload()
} else {
toast.error('Unable to post')
}
} else {
toast.error('File upload is not complete')
}
} else {
toast.error('Something went wrong')
}
} catch (error) {
toast.error('Something went wrong')
}
} else {
toast.error('You need to sign in')
}
}, [vname, selectedValue, user, uppy])
dave
05/08/2023, 5:20 PMsupabase.auth.admin.generateLink
and then use that to sign in, but that feels so unnecessary.drewbie
05/08/2023, 5:43 PMslug
column on the products
table that has a non null constraint. The slug is generated in a before insert/update trigger on the products table, however when I try to insert a products record, the slug column is required in the types even though technically its not needed for the insert to succeed. Any thoughts?Amr
05/08/2023, 5:43 PMts
export async function getFileSignedURLs(filePaths: string[],expire = 120) {
const { data, error } = await supabase.storage
.from('user-id-photos')
.createSignedUrls(filePaths, expire);
if (error) {
console.error('๐ Error getting file signed URL: ', error.message);
return [];
}
console.log(data[0]);
return data;
}
The console.log(data[0]);
outputs this:
js
{
error: null,
signedURL: '/object/sign/user-id-photos/2454d3f9-fe1e-47e0-bf08-2b53c6c63ada.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cmwiOiJ1c2VyLWlkLXBob3Rvcy8yNDU0ZDNmOS1mZTFlLTQ3ZTAtYmYwOC0yYjUzYzZjNjNhZGEuanBnIiwiaWF0IjoxNjgzNTY3Mzc3LCJleHAiOjE2ODM1NzA5Nzd9.7Ep_LFygXHGO7rBQsF65dC_y94RoarUslDsbAeqy710',
signedUrl: 'http://localhost:54321/storage/v1/object/sign/user-id-photos/2454d3f9-fe1e-47e0-bf08-2b53c6c63ada.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cmwiOiJ1c2VyLWlkLXBob3Rvcy8yNDU0ZDNmOS1mZTFlLTQ3ZTAtYmYwOC0yYjUzYzZjNjNhZGEuanBnIiwiaWF0IjoxNjgzNTY3Mzc3LCJleHAiOjE2ODM1NzA5Nzd9.7Ep_LFygXHGO7rBQsF65dC_y94RoarUslDsbAeqy710'
}
As you can see, signedUrl
is duplicate, and there's no path
!sili
05/08/2023, 6:17 PMtina
05/08/2023, 7:13 PMsql
CREATE POLICY "Enable read access for all users" ON "public"."profiles"
AS PERMISSIVE FOR SELECT
TO public
USING (true)
sql
CREATE POLICY "Enable insert for everyone" ON "public"."profiles"
AS PERMISSIVE FOR INSERT
TO public
WITH CHECK (true)
Another strange thing is that I have to stringify the object with the data I'm about to post, otherwise I'm getting a "new row violates row-level security policy for table" error. With this stringified object I'm getting the status 201 and no error + no data in the table ๐ข๓ ๓
05/08/2023, 7:45 PMts
const handleLoginWithKey = async () => {
if (!challenge) return
const token = await loginKey({challenge})
await manuallySetUser(token)
}
for manuallySetUser, this uses the Supabase provider context to replace the browser client with one that has the authorization header set
ts
export default function SupabaseProvider({children}: { children: React.ReactNode }) {
const [supabase, setSupabase] = useState(() => createBrowserSupabaseClient())
/* relevant code */
const manuallySetUser = async (access_token: string) => setSupabase(() =>
createBrowserSupabaseClient({
supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL!,
supabaseKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
options: { global: { headers: {
authorization: `Bearer ${access_token}`,
}}}
})
/* */
useEffect(() => {
// refresh route on auth change
}, [router, supabase])
useEffect(() => {
if (!supabase) return
getUser()
}, [supabase])
return (
<Context.Provider value={{ supabase: supabase, user, manuallySetUser }}>
<>{children}</>
</Context.Provider>
)
}
export const useSupabase = () => {
const context = useContext(Context)
if (context === undefined) throw new Error('useSupabase must be used inside SupabaseProvider')
return context
}
this ALMOST works, it fails however because for some reason the bearer token is appended rather than set.
When looking at the supabase.co/auth/v1/user
request, this is the authorization header:
Bearer header.anon_data, Bearer header.manually_set_data
which as expected isn't parsed by the auth api, {"code":401,"msg":"This endpoint requires a Bearer token"}
FoxAxeFin
05/08/2023, 8:22 PMWaba-tron
05/08/2023, 9:02 PMhttps://cdn.discordapp.com/attachments/1105238352782958682/1105238352992669809/Screenshot_2023-05-08_at_21.54.08.pngโพ
ven
05/08/2023, 9:09 PM// @ts-ignore: module not found
import { SupabaseClient } from '@supabase/supabase-js';
and here is my import_maps
{
"imports": {
"@supabase/supabase-js": "https://esm.sh/@supabase/supabase-js@2.7.1",
"asserts": "https://esm.sh/v119/*asserts@4.0.2",
"denomailer": "https://esm.sh/v119/denomailer@0.0.0",
"lodash": "https://esm.sh/v119/lodash@4.17.21",
"oak": "https://deno.land/x/oak/mod.ts",
"server": "https://deno.land/std/http/server.ts",
"zod": "https://esm.sh/v119/zod@3.21.4",
"stripe": "https://esm.sh/stripe@11.1.0?target=deno"
}
}
I am using VS Code.Hugos
05/08/2023, 9:27 PMjs
const { data, error } = await supabase
.from('product_groups')
.select(
`
id,
name,
description,
images,
products ( * )
`
)
This works great, but I need only products where the ``active`` column is set to ``true``, is this possible? I've created a view that does that for me right now but if it's possible without I might aswellmccombs
05/08/2023, 9:35 PM[]
I've tried both queries: realtime_memory_bytes{supabase_project_ref="oocsbdgwapewiegksepf",service_type="middleware"}
and realtime_memory_bytes{service_type=\"middleware\"} / 1000 / 1000
Am I missing something? Are my queries malformated?
I am able to connect to my endpoint via curl and return data. So I know my endpoint and service provider key are valid.
Here's the Curl response I get
# HELP realtime_memory_bytes Current realtime memory usage
# TYPE realtime_memory_bytes gauge
realtime_memory_bytes{supabase_project_ref="oocsbdgwapewiegksepf",service_type="middleware"} 1.8446744073709552e+19
Here's the grafana request and response:
{
"request": {
"url": "api/ds/query",
"method": "POST",
"data": {
"response": {
"results": {
"A": {
"status": 200,
"frames": [
{
"schema": {
"refId": "A",
"meta": {
"typeVersion": [
0,
0
],
"executedQueryString": "Expr: realtime_memory_bytes{service_type=\\\"middleware\\\"} / 1000 / 1000\nStep: 15s"
},
"fields": []
},
"data": {
"values": []
}
}
],
"refId": "A"
}
}
}
}
root
05/08/2023, 10:06 PMconfig.toml
checked in to source control?Fisher
05/08/2023, 10:49 PMrovrav
05/08/2023, 11:33 PMhttps://cdn.discordapp.com/attachments/1105276341139542126/1105276341349265498/image.pngโพ
https://cdn.discordapp.com/attachments/1105276341139542126/1105276341747720223/image.pngโพ
https://cdn.discordapp.com/attachments/1105276341139542126/1105276342116814918/image.pngโพ
garyaustin
05/09/2023, 12:44 AMcatwithakeyboard
05/09/2023, 1:08 AMyayza_
05/09/2023, 1:58 AMjs
const categoryId = url.searchParams.get("categoryId"); // 34
const { data: results, error: attributesError } = await locals.supabase.from("attribute").select("*, category_attribute(*)").eq("category_attribute.category_id", categoryId);
console.log(JSON.stringify(results, null, 2));
Outputs this:
[
{
attribute_id: 16,
attribute_name: "Color",
attribute_description: null,
attribute_image_path: null,
category_attribute: [
{
id: 120,
category_id: 34,
attribute_id: 16,
},
],
},
{
attribute_id: 6,
attribute_name: "Manufacturer",
attribute_description: null,
attribute_image_path: null,
category_attribute: [],
},
];
Not sure what I'm doing wrong here ๐คPing
05/09/2023, 2:17 AMhttps://<myID>.supabase.co/storage/v1/object/public/model_thumbnails/imaged.jpg
works.
However, everytime i try to resize it using this URL https://<myID>.supabase.co/storage/v1/render/image/public/model_thumbnails/imaged.jpg?width=800&height=300&resize=contain
it fails and returns an error saying :
json
{"statusCode":"403","error":"FeatureNotEnabled","message":"feature not enabled for this tenant"}
ven
05/09/2023, 2:43 AMError: unknown flag: --import-map
.
here is my simple yaml
name: Deploy Function
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
PROJECT_ID: zkcmpwzbigjgwiesauro
steps:
- uses: actions/checkout@v3
- uses: supabase/setup-cli@v1
with:
version: 1.0.0
- run: supabase functions deploy contact --import-map=../../supabase/functions/import_map.json --project-ref $PROJECT_ID
Has anyone had luck with github actions where the import map is not at the root?garyaustin
05/09/2023, 3:12 AMvinciarts
05/09/2023, 3:20 AMJackson Sophat
05/09/2023, 6:26 AMint8
to uuid
Thank you
https://cdn.discordapp.com/attachments/1105380274604343337/1105380274772127764/image.pngโพ
lekt9
05/09/2023, 7:17 AMtowc
05/09/2023, 7:40 AMven
05/09/2023, 8:43 AMSchema drift refers to any difference between the expected schema (based on your migration history and schema.prisma file) and the actual schema in your database. There isnโt specific documentation that lists all common schema drift causes, but some possible reasons for drift include: Manual changes to the database schema, such as adding or modifying tables, columns, indexes, constraints outside of Prisma Migrate. Incomplete or failed migrations, which leave the schema in an inconsistent state.
Changes to the schema.prisma file that have not been applied as migrations.
Here's my problem. 9 times out of 10 those reasons don't apply to my schema drift. 9 times out of 10 the only thing i have done is added/updated/deleted test data. which is what a database is for, right? So, as a temporary fix I stopped using Prisma migrations altogether and switch to prisma db push
forcing schema changes. I want to hear how people are managing their migrations. What workflows are you using? cc: @NanoBitRevaycolizer
05/09/2023, 8:48 AMconst handlePost = useCallback(async () => {
if (user) {
try {
if (vfile) {
const upload = new tus.Upload(vfile, {
endpoint: `https://${projectId}.supabase.co/storage/v1/upload/resumable`,
retryDelays: [0, 3000, 5000, 10000, 20000],
headers: {
authorization: `Bearer ${token}`,
'x-upsert': 'true', // optionally set upsert to true to overwrite existing files
},
uploadDataDuringCreation: true,
metadata: {
bucketName: 'files',
objectName: vname,
contentType: 'image/png',
cacheControl: 3600,
},
chunkSize: 6 * 1024 * 1024, // NOTE: it must be set to 6MB (for now) do not change it
onError: function (error) {
console.log('Failed because: ' + error)
toast.error('something went wrong')
},
onProgress: function (bytesUploaded, bytesTotal) {
var percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2)
console.log(bytesUploaded, bytesTotal, percentage + '%')
},
onSuccess: function () {
setFile_url(upload.url)
},
})
upload.start()
}
if (vname) {
const data = await supabase.from('category').insert({
vname: vname,
selectedValue: selectedValue.category,
user: user,
})
if (data && vname && vfile) {
toast.success('Post uploaded successfully')
setOpen(false)
location.reload()
} else {
toast.error('Unable to post')
}
}
} catch (error) {
toast.error('Something went wrong')
}
} else {
toast.error('You need to sign in')
}
}, [vname, vfile, selectedValue, user])
Whoman
05/09/2023, 10:29 AMhttps://cdn.discordapp.com/attachments/1105441283150991390/1105441283364892763/image.pngโพ
Bad Gifter
05/09/2023, 10:41 AMcurl -X POST \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer REDACTED' \
-d $'{
"tenant" : {
"name": "supabase_realtime_rls",
"external_id": "supabase-supabase-realtime",
"jwt_secret": "REDACTED_JWT",
"extensions": [
{
"type": "postgres_cdc_rls",
"settings": {
"db_name": "postgres",
"db_host": "supabase-db.postgres.svc.cluster.local",
"db_user": "postgres",
"db_password": "REDACTED",
"db_port": "5432",
"region": "fra",
"poll_interval_ms": 100,
"poll_max_record_bytes": 1048576,
"ip_version": 4
}
}
]
}
}' \
http://localhost:62042/api/tenants
The url for the api ends up referencing an internal url that starts with supabase-supabase-realtime. Hence the external_id is set to that which solved one issue.
Next issue now is I am getting "unmatched topic" error on the front-end. I pulled the logs of the realtime bucket and it shows this.
presence_key: "REDACTED", rate_counter: %Realtime.RateCounter{id: {:channel, :events, "supabase-supabase-realtime"}, avg: 0.5, bucket: [1, 0], max_bucket_len: 60, tick: 1000, tick_ref: #Reference<0.1672614097.2835611650.128683>, idle_shutdown: :infinity, idle_shutdown_ref: nil, telemetry: %{emit: true, event_name: [:realtime, :rate_counter, :channel, :events], measurements: %{limit: 100, sum: 0}, metadata: %{id: {:channel, :events, "supabase-supabase-realtime"}, tenant: "supabase-supabase-realtime"}}}, self_broadcast: false, tenant: "supabase-supabase-realtime", tenant_token: "REDACTED_TOKEN", tenant_topic: "supabase-supabase-realtime:public"}, channel: RealtimeWeb.RealtimeChannel, channel_pid: #PID<0.3183.0>, endpoint: RealtimeWeb.Endpoint, handler: RealtimeWeb.UserSocket, id: "user_socket:supabase-supabase-realtime", joined: true, join_ref: "4", private: %{log_handle_in: :debug, log_join: :info}, pubsub_server: Realtime.PubSub, ref: nil, serializer: Phoenix.Socket.V1.JSONSerializer, topic: "realtime:public", transport: :websocket, transport_pid: #PID<0.3181.0>}
09:56:31.206 project=supabase-supabase-realtime [info] Billing metrics: [:realtime, :rate_counter, :channel, :events]
09:56:31.208 project=supabase-supabase-realtime [info] Billing metrics: [:realtime, :rate_counter, :channel, :joins]
09:56:31.534 project=supabase-supabase-realtime external_id=supabase-supabase-realtime [error] GenServer #PID<0.3186.0> terminating
** (FunctionClauseError) no function clause matching in Realtime.PostgresCdc.region_nodes/1
(realtime 2.7.1) lib/realtime/postgres_cdc.ex:89: Realtime.PostgresCdc.region_nodes(nil)
(realtime 2.7.1) lib/realtime/postgres_cdc.ex:104: Realtime.PostgresCdc.launch_node/3
(realtime 2.7.1) lib/extensions/postgres_cdc_rls/cdc_rls.ex:71: Extensions.PostgresCdcRls.start_distributed/1
(realtime 2.7.1) lib/extensions/postgres_cdc_rls/cdc_rls.ex:16: anonymous fn/3 in Extensions.PostgresCdcRls.handle_connect/1
(elixir 1.14.3) lib/range.ex:392: Enumerable.Range.reduce/5
(elixir 1.14.3) lib/enum.ex:2514: Enum.reduce_while/3
(realtime 2.7.1) lib/realtime_web/channels/realtime_channel.ex:288: RealtimeWeb.RealtimeChannel.handle_info/2
(phoenix 1.6.13) lib/phoenix/channel/server.ex:343: Phoenix.Channel.Server.handle_info/2
I'm clueless. I notice there is no pg_create_logical_replication_slot being run so no logical slot was made. Assuming there's an error before that occurs ... any help?Stormii
05/09/2023, 11:17 AM%${seria}%
)
.order('name')
.then(wynik => {
return wynik.data;
});
https://cdn.discordapp.com/attachments/1105453480363180153/1105453480577085511/image.pngโพ