Unable to CreateClient due to invalid Project Url

I am creating a upload service where I am using multer and supabase with expressJs. While creating supabase client its throwing the invalid_url error and adding /auth/v1 to url (weird?) Unable to fix it for hour now imageController - https://pastecord.com/yzevytaquj.typescript StorageClient - https://pastecord.com/fudinyzupe.typescript
37 Replies
Mr. Limbo
Mr. LimboOP8mo ago
The dashboard is showing the same url used in my env file but its not accesible through browser
garyaustin
garyaustin8mo ago
Logout your config.PROJECT_URL in your createClient code.
Mr. Limbo
Mr. LimboOP8mo ago
it was correct currently I switch it to use storage client directly through supabase/storage package and it seems to work Why does supabse add extra string to url? I am trying to upload the image and get the data and its throwing this error
{
code: 'ERR_INVALID_URL',
input: '"https://evaxcywvwsgcqknqtckv.supabase.co/";/object/images/1736814689052_fractal.jpg'
}
{
code: 'ERR_INVALID_URL',
input: '"https://evaxcywvwsgcqknqtckv.supabase.co/";/object/images/1736814689052_fractal.jpg'
}
code - https://pastecord.com/pybigupebo.typescript
Mr. Limbo
Mr. LimboOP8mo ago
@garyaustin I am using unix time to create storagepath, using the same structure defined in the docs. https://supabase.com/docs/reference/javascript/storage-from-upload
JavaScript: Upload a file | Supabase Docs
Supabase API reference for JavaScript: Upload a file
Mr. Limbo
Mr. LimboOP8mo ago
the same thing was happening with createClient but for now I fixed it using storage library and creating it directly
garyaustin
garyaustin8mo ago
Supabase initiated with the base url in supabase-js will not add anything to the url. Then each component (auth/storage/postgrest) adds it's bit of url like /storage/v1. After that the file name gets added. Your code above looks like you are hand setting the storage url to "https:// evaxcywvwsgcqknqtckv.supabase.co/";/object . The storage then adds your path /images/blah.jbp to it. Very few use storage.js/auth.js/postgres.js directly.
Mr. Limbo
Mr. LimboOP8mo ago
but I am not this is the console.log response project_url is https://evaxcywvwsgcqknqtckv.supabase.co/ from config file
garyaustin
garyaustin8mo ago
No one is reporting bugs with the js client and it would be major if it was. You are most likely doing something wrong in setting it up, or passing the client around if you are doing serverside stuff.
Mr. Limbo
Mr. LimboOP8mo ago
the whole code where client is used is there and I can't really find the bug in that one and the last one where client variable is used is config file
require('dotenv').config();

const PORT = process.env.PORT || 3000;
const JWT_SECRET = process.env.JWT_SECRET;
const REFRESH_SECRET = process.env.REFRESH_SECRET;
const PROJECT_URL = process.env.PROJECT_URL;
const API_KEY = process.env.API_KEY;

module.exports = { PORT, JWT_SECRET, REFRESH_SECRET, PROJECT_URL, API_KEY };
require('dotenv').config();

const PORT = process.env.PORT || 3000;
const JWT_SECRET = process.env.JWT_SECRET;
const REFRESH_SECRET = process.env.REFRESH_SECRET;
const PROJECT_URL = process.env.PROJECT_URL;
const API_KEY = process.env.API_KEY;

module.exports = { PORT, JWT_SECRET, REFRESH_SECRET, PROJECT_URL, API_KEY };
which is giving a correct output
garyaustin
garyaustin8mo ago
I have no idea what multer is and don't use express.js. But if you pass supabase-js the correct project then it will work for all components.
Mr. Limbo
Mr. LimboOP8mo ago
ok i'll try to fix it
garyaustin
garyaustin8mo ago
If you have multiple createClients for different server components (as you are doing Express) maybe your clients are not getting the initialization pass around. If your storage call url you show is real, then somewhere the storage.url got set the string clip I showed, including the quotes which looks like bad code to me or somehow a string being double quoted.
Mr. Limbo
Mr. LimboOP8mo ago
yeah the string is getting quoted somewhere in between
garyaustin
garyaustin8mo ago
Oh the object is part of the storage adding it. So it is just the string is being double quoted. The semicolon in the string is odd too.
Mr. Limbo
Mr. LimboOP8mo ago
yeah
garyaustin
garyaustin8mo ago
And seems to be from client code.
Mr. Limbo
Mr. LimboOP8mo ago
client is just a postman request with the image and content-type
garyaustin
garyaustin8mo ago
I meant your code setting up supabase, not the browser client.
Mr. Limbo
Mr. LimboOP8mo ago
this is supabase setup, can't see anything odd here.
const { StorageClient } = require('@supabase/storage-js');
const config = require('./config');
const supabaseUrl = config.PROJECT_URL;
const supabaseKey = config.API_KEY;
module.exports = new StorageClient(supabaseUrl, {
apikey: supabaseKey,
Authorization: `Bearer ${supabaseKey}`,
});
const { StorageClient } = require('@supabase/storage-js');
const config = require('./config');
const supabaseUrl = config.PROJECT_URL;
const supabaseKey = config.API_KEY;
module.exports = new StorageClient(supabaseUrl, {
apikey: supabaseKey,
Authorization: `Bearer ${supabaseKey}`,
});
garyaustin
garyaustin8mo ago
storage client does not take supabaseUrl. It has to have /storage/v1 added on to it.
Mr. Limbo
Mr. LimboOP8mo ago
oh right
garyaustin
garyaustin8mo ago
As I said very few deal with the sub REST clients directly. Maybe your config as double quotes around it and it shouldn't.
Mr. Limbo
Mr. LimboOP8mo ago
what do you mean by this
garyaustin
garyaustin8mo ago
Almost everyone uses supabase-js, not storage-js/auth-js/realtime-js/postgrest-js. process.env.PROJECT_URL; Maybe that has double quotes around it.
Mr. Limbo
Mr. LimboOP8mo ago
there are no downside with using them standalone right?
garyaustin
garyaustin8mo ago
It is much hard for some of them. Storage is fairly clean, but like you entered the Authorization header, maybe that works, I've not looked. Just saying docs are not great on them and hardly anyone I've helped uses them.
Mr. Limbo
Mr. LimboOP8mo ago
ok I see. Thanks 👍
garyaustin
garyaustin8mo ago
Find your extra double quote and then add /storage/v1 and that should solve your storage client url issue.
Mr. Limbo
Mr. LimboOP8mo ago
sure
garyaustin
garyaustin8mo ago
Some configs/env files don't need quotes around strings I believe.
garyaustin
garyaustin8mo ago
No description
Mr. Limbo
Mr. LimboOP8mo ago
hmm but I believe dotenv trim the quotes not sure
garyaustin
garyaustin8mo ago
Supabase does not add them...
Mr. Limbo
Mr. LimboOP8mo ago
supabase doesn't add env var with strings?
garyaustin
garyaustin8mo ago
supabase will not add double quotes to the url you provide.
garyaustin
garyaustin8mo ago
The few examples I see don't have quotes for expressjs env file.
No description
Mr. Limbo
Mr. LimboOP8mo ago
yeah I get that as they are URL object, not sure which part is stringifying the url. Not using quoted url this time. Let me find this bug on my won own* Fixed : By just saving the file and reloading. Not sure why, maybe cached.

Did you find this page helpful?