COLD1
04/14/2023, 7:16 PMjavascript
require('dotenv').config({ path: __dirname + '/../../.env' });
const { body, validationResult } = require('express-validator');
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_ANON_KEY;
const { createClient } = require('@supabase/supabase-js');
const supabase = createClient(supabaseUrl, supabaseKey);
// const csrf = require('csrf');
const { v4: uuidv4 } = require('uuid');
// POST /articles
exports.createArticle = [
// Use express-validator middleware for input validation
body('author_id').isInt(),
body('article_title').notEmpty(),
body('summary').notEmpty(),
body('content').notEmpty(),
async (req, res, next) => {
const client = await supabase.pool.connect(); // acquire a connection from the pool
try {
await client.query('BEGIN ISOLATION LEVEL SERIALIZABLE'); // begin a transaction with serializable isolation level
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
const { data: maxArticleId, error: maxArticleIdError } = await supabase
.from('articles')
.select('MAX(article_id) as max_article_id');
if (maxArticleIdError) {
await client.query('ROLLBACK'); // rollback the transaction if an error occurred
return next(maxArticleIdError);
}
const nextArticleId = maxArticleId[0].max_article_id + 1;
const { data: article, error } = await supabase
.from('articles')
.insert({
article_id: nextArticleId,
author_id: req.body.author_id,
article_title: req.body.article_title,
summary: req.body.summary,
content: req.body.content,
});
if (error) {
await client.query('ROLLBACK'); // rollback the transaction if an error occurred
return next(error);
}
await client.query('COMMIT'); // commit the transaction if there were no errors
res.json({ message: 'Article created successfully!' });
} catch (error) {
await client.query('ROLLBACK'); // rollback the transaction if an error occurred
next(error);
} finally {
client.release(); // release the connection back to the pool
}
},
];
.Volxen
04/14/2023, 7:18 PMGui BL
04/14/2023, 7:27 PMremaining connection slots are reserved for non-replication superuser connections
I'm not a pro on connection pooling and such but I think this comes from me sending multiple requests and the connection pool becoming busy. If I restart the server in the dashboard all works fine but I would like tips on avoiding this issue in the future. How would I best setup my connection pool?zxkevinxz
04/14/2023, 8:27 PMJere
04/14/2023, 9:00 PMriccardolardi
04/14/2023, 9:22 PMFisher
04/14/2023, 9:57 PMkylelovesyou
04/14/2023, 10:19 PMnlarusstone
04/15/2023, 12:16 AMsupabase db remote commit
creates a migration file with the following commands in it:
alter table "storage"."buckets" add column "allowed_mime_types" text[];
alter table "storage"."buckets" add column "avif_autodetection" boolean default false;
alter table "storage"."buckets" add column "file_size_limit" bigint;
alter table "storage"."objects" add column "version" text;
But when I start the server using supabase start
I get the following error:
Error: Migration failed. Reason: An error occurred running 'add-automatic-avif-detection-flag'. Rolled back this migration. No further migrations were run. Reason: column "avif_autodetection" of relation "buckets" already exists
This happens even from a fresh start.
If I remove those commands from the migration script, the DB can start, but the commands get added back in the next time i try to commit from remotedperolio
04/15/2023, 12:24 AMapp
directory, I'm getting the following errors:
> 8:22:11 PM: Error occurred prerendering page "/register". Read more: https://nextjs.org/docs/messages/prerender-error
> 8:22:11 PM: Error: either NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY env variables or supabaseUrl and supabaseKey are required!
> 8:22:11 PM: at createServerComponentSupabaseClient (/opt/build/repo/.next/server/chunks/128.js:140:15)
> 8:22:11 PM: at Home (/opt/build/repo/.next/server/app/register/page.js:478:120)
> 8:22:11 PM: at S (/opt/build/repo/.next/server/chunks/722.js:17648:13)
> 8:22:11 PM: at Ua (/opt/build/repo/.next/server/chunks/722.js:17745:21)
> 8:22:11 PM: at Object.toJSON (/opt/build/repo/.next/server/chunks/722.js:17576:20)
> 8:22:11 PM: at stringify ()
> 8:22:11 PM: at da (/opt/build/repo/.next/server/chunks/722.js:17135:9)
> 8:22:11 PM: at bb (/opt/build/repo/.next/server/chunks/722.js:17841:30)
> 8:22:11 PM: at Timeout._onTimeout (/opt/build/repo/.next/server/chunks/722.js:17698:16)
> 8:22:11 PM: at listOnTimeout (node:internal/timers:559:17)
> 8:22:11 PM: info - Generating static pages (3/7)
> 8:22:11 PM: Error occurred prerendering page "/login". Read more: https://nextjs.org/docs/messages/prerender-error
> 8:22:11 PM: Error: either NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY env variables or supabaseUrl and supabaseKey are required!
> 8:22:11 PM: at createServerComponentSupabaseClient (/opt/build/repo/.next/server/chunks/128.js:140:15)
> 8:22:11 PM: at Home (/opt/build/repo/.next/server/app/login/page.js:498:120)
> 8:22:11 PM: at S (/opt/build/repo/.next/server/chunks/722.js:17648:13)
> 8:22:11 PM: at Ua (/opt/build/repo/.next/server/chunks/722.js:17745:21)
> 8:22:11 PM: at Object.toJSON (/opt/build/repo/.next/server/chunks/722.js:17576:20)
> 8:22:11 PM: at stringify ()
> 8:22:11 PM: at da (/opt/build/repo/.next/server/chunks/722.js:17135:9)
> 8:22:11 PM: at bb (/opt/build/repo/.next/server/chunks/722.js:17841:30)
> 8:22:11 PM: at Timeout._onTimeout (/opt/build/repo/.next/server/chunks/722.js:17698:16)
> 8:22:11 PM: at listOnTimeout (node:internal/timers:559:17)
> 8:22:11 PM: info - Generating static pages (5/7)
> 8:22:11 PM: info - Generating static pages (7/7)
> 8:22:11 PM: > Export encountered errors on following paths:
> 8:22:11 PM: /api/test/route: /api/test
> 8:22:11 PM: /login/page: /login
> 8:22:11 PM: /page: /
> 8:22:11 PM: /register/page: /register
> 8:22:12 PM:
> 8:22:12 PM: "build.command" failednaveeng2402
04/15/2023, 1:29 AMykisana
04/15/2023, 1:57 AMevent.locals.supabase = createSupabaseServerClient({
supabaseUrl: PUBLIC_SUPABASE_URL,
supabaseKey: PUBLIC_SUPABASE_ANON_KEY,
event
});
I have a POST request defined as follow POST: RequestHandler = async ({ request, locals: { supabase, getSession } })
This is in a +server.ts
file in a route. First I wanted to protect the API, so I did this, as per the docs:
const session = await getSession();
if (!session) {
// the user is not signed in
throw new Error('Unauthorized');
}
This seems to work, I don't see the error.
But then I try doing this:
const { error } = await supabase
.from('messages')
.insert({ message: message) });
And get the following error:
error: {
code: '42501',
details: null,
hint: null,
message: 'permission denied for schema public'
}
I've tried with my Secret Key as-well, so updating it to supabaseKey: PUBLIC_SUPABASE_SECRET_KEY
in hooks.server.ts
. And the same error occurs. I've confirmed that the .env vars are correct. And these should be the same as on the client, and auth works so no issue there.leovigildo
04/15/2023, 2:27 AMdperolio
04/15/2023, 3:13 AMts
import { createMiddlewareSupabaseClient } from '@supabase/auth-helpers-nextjs';
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export async function middleware (req: NextRequest) {
const res = NextResponse.next();
const supabase = createMiddlewareSupabaseClient({ req, res });
await supabase.auth.getSession();
return res;
}
In particular, it's saying createMiddlewareSupabaseClient
needs it.kylelovesyou
04/15/2023, 3:39 AMHartaithan
04/15/2023, 3:44 AMproro485
04/15/2023, 3:55 AMhttps://cdn.discordapp.com/attachments/1096645062114422895/1096645062399623278/Screenshot_from_2023-04-15_09-24-45.png▾
https://cdn.discordapp.com/attachments/1096645062114422895/1096645062680657990/Screenshot_from_2023-04-15_09-25-12.png▾
Wizzel
04/15/2023, 8:15 AMMDobs
04/15/2023, 8:41 AMhichana
04/15/2023, 9:03 AMconst { data, error } = await supabase.rpc('hello_world')
In typescript, the following error is thrown:
Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345)
To mitigate the error I had to add a custom typescript definition for the supabase client:
// supabaseCustom.d.ts
import { PostgrestBuilder } from '@supabase/postgrest-js';
import { SupabaseClient } from '@supabase/supabase-js';
declare module '@supabase/supabase-js' {
interface SupabaseClient {
rpc<ResponseType, ParamsType>(
fn: string,
params?: ParamsType
): PostgrestBuilder<ResponseType>;
}
}
I think I'll add an issue to the javascript repo, but placing it here in case it helps anyone else.ws
04/15/2023, 9:35 AMlet session = try await supabase.auth.session(from: url)
but no auth event fired.
It worked yesterday, maybe supabase outage ?AlleyCat
04/15/2023, 12:31 PMSELECT * FROM cron.job
https://cdn.discordapp.com/attachments/1096774848916762737/1096774966814441563/image.png▾
marc
04/15/2023, 1:14 PM/functions/_core/dbtypes.ts
file into /functions/_api/supabase.ts
but I don't understand how the files are loaded,
I use the import map with
{
"imports": {
"/": "./",
"./": "./"
}
}
if you can help me to understand how to have code shared globally between all folders _
or how to set up a global runtime to define some code before all execution
tanks for your time ❤️
https://cdn.discordapp.com/attachments/1096785593175908515/1096785593448529990/Capture_decran_2023-04-15_a_15.11.32.png▾
https://cdn.discordapp.com/attachments/1096785593175908515/1096785593758920796/Capture_decran_2023-04-15_a_15.13.54.png▾
khairulhaaziq
04/15/2023, 1:27 PMsalzar
04/15/2023, 1:49 PMunexpected response while creating upload, originated from request (method: POST, url: https://wmsccjgcrykictvgimtt.supabase.co/storage/v1/upload/resumable, response code: 404, response text: {"message":"Route POST:/upload/resumable not found","error":"Not Found","statusCode":404}, request id: n/
altechzilla
04/15/2023, 4:19 PMArinji
04/15/2023, 4:30 PMshnoman
04/15/2023, 4:49 PMsupaClient
.from('messages')
.stream(primaryKey: ['id'])
.order('createdAt')
TimurKramar
04/15/2023, 5:08 PMgetUser()
I get a weird error: ```"AuthApiError: invalid claim: missing sub claim
at eval (webpack-internal:///(app-client)/./node_modules/@supabase/gotrue-js/dist/module/lib/fetch.js:49:20)"```I inspected the logs for the API Edge network, and it receives a GET request at path /auth/v1/user
, and the logs for auth show request at path /user
with the error missing sub claim.Canman
04/15/2023, 5:21 PM