Ganbatte
Explore posts from serversDTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
I managed to solve it in the meantime. In case someone comes across this, I had to run this SQL:
GRANT USAGE ON SCHEMA public TO authenticated;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO authenticated;
This grants the authenticated user permission to see the public schema, if I understand correctly. Without this, I couldn’t even see the tables.
Thanks for the help, everyone!42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
So, if I understand correctly, the focus here isn’t just on what I’m passing but rather on something more complex, which is why I should use this: https://authjs.dev/getting-started/adapters/supabase, right?
The problem is that when I integrated it into my code, even the login stopped working, and it threw an error I couldn’t even find any information about. It couldn’t find the supabaseAccessToken part in the file. I don’t really understand the SQL part of it, but as far as I saw, it placed the tables in a separate schema, and from then on, Drizzle didn’t even allow me to reference them (e.g., it used user.id in other tables).
On top of that, this package is barely used, and it’s made very clear that there’s no dedicated maintainer for it. From what I can see—but feel free to correct me—it seems like Auth.js has been in beta for over a year, and the project looks somewhat neglected. Everyone on Reddit says that Better Auth will replace Auth.js, but unfortunately, it’s so new that I didn’t dare to switch to it.
I also tried SupabaseAuth in the morning, hoping it might solve this issue, even if it meant losing some of Auth.js’s flexibility. But since I’m self-hosting, as far as I could tell, the auth part isn’t included in the self-hosted version by default. You can only configure it with random .env files, which lack proper documentation, and everyone I’ve seen on StackOverflow and GitHub is struggling with it.
If you can help with this in any way, I’d appreciate it! I use GitHub and Google auth in the project, and I don’t have major requirements, subdomain routing for auth is the only more important aspect.
I’ll give it another try tomorrow, but any help would be greatly appreciated. Thanks in advance!
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
Thanks for the info, but why exactly is it necessary to make the auth.js token compatible with Supabase? I don’t fully understand this part, and if you could also kindly answer my previous question, I’d really appreciate it. This is what I’m referring to:
My problem begins with the fact that I can’t find where you export the db object, so I can’t reference it anywhere in my code. Why should I export it?
I also don’t fully understand how this data fetching, editing works with RLS.
For example, I’m referring to this:
const db = await createDrizzleSupabaseClient();
const [user] = await db.rls((tx) =>
tx.select().from(profiles).where(eq(profiles.email, email))
);
Thanks in advance!42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
Now I understand the whole thing better. I went for a swim, and now I’ve started working on the implementation again, but unfortunately, I got stuck.
I created the PostgreSQL user and the .env files as you mentioned. I also implemented the jws.ts and drizzle.ts files based on your repository, and I rewrote the index.ts file (which I believe is called db.ts in your case).
My problem begins with the fact that I can’t find where you export the db object, so I can’t reference it anywhere. I also don’t fully understand how this data fetching, editing works with RLS.
For example, I’m referring to this:
const db = await createDrizzleSupabaseClient();
const [user] = await db.rls((tx) =>
tx.select().from(profiles).where(eq(profiles.email, email))
);
And that was the simpler part. I checked the documentation Darren mentioned about Supabase-compatible tokens for Auth.js:
https://authjs.dev/getting-started/adapters/supabase
If this is what he’s referring to, honestly, I don’t really understand how I should integrate it into your codebase.
Thanks in advance if you have any suggestions!42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
First of all, thank you both for all these helpful messages. I agree with you on the complexity, it does indeed seem quite complex, especially from my perspective. I’m new to the backend world, and while I’ve been using Supabase for about a year, my knowledge of PostgreSQL and SQL is very limited.
That said, I really like Drizzle. Before that, I used Prisma, but I prefer Drizzle. I like that it doesn’t hide what it’s doing under a lot of "magic," it’s fast, and it’s easy to create views with it, etc.
If this was my previous DATABASE_URL:
postgres://postgres:mySupabasePostgresPW@myServerIp:5432/postgres
then with RLS it would be this, right?
postgres://rls_client:mySupabasePostgresPW@myServerIp:5432/postgres
The SQL you sent, should that be run in Supabase? Does it establish the base for the connection that I’ll link to the RLS URL? (process.env.DATABASE_URL)
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/27/2024 in #help
Why Isn't RLS Working with Drizzle and Supabase?
Thank you so much, both of you. I went through the README and the files @rphlmr ⚡ , and to be honest, I felt quite disheartened seeing how much extra complexity this involves. +3 config files, and I also had to add a bunch of stuff to my existing config files. Also, from what I can see, the Supabase SSR package seems to be mandatory for this. Or is this SSR package only necessary for the auth part?
Does this RLS actually work without Supabase Auth? Because I’m using auth.js. From what I can tell, it seems like it relies on the built-in roles of Supabase. I’ve created my own enum for roles, and this is connected to my user table. Thanks in advance!
42 replies
DTDrizzle Team
•Created by Ganbatte on 11/9/2024 in #help
Issues Using RLS with Supabase Through Drizzle
First of all, thanks for your response. Could you please describe exactly what you mean? Sorry, I'm just very new to backend stuff.
4 replies
DTDrizzle Team
•Created by Ganbatte on 10/25/2024 in #help
Middleware Issues in Next.js Using Drizzle, Supabase, and NextAuth
Thanks for the suggestion! I’m a bit confused, though since the documentation link you sent seems to focus on Cloudflare workers, which is a bit different from Next.js. Were you suggesting I should configure something in next.config.js? My connection string in the environment variables works fine, and I set up Drizzle according to the documentation on their site (I shared the setups in the screenshots above). Could you help clarify what you think might be causing the issue?
9 replies
DTDrizzle Team
•Created by Ganbatte on 10/25/2024 in #help
Middleware Issues in Next.js Using Drizzle, Supabase, and NextAuth
9 replies
DTDrizzle Team
•Created by Ganbatte on 10/25/2024 in #help
Middleware Issues in Next.js Using Drizzle, Supabase, and NextAuth
I'm sure that Drizzle is causing the problem because I separated the auth into edge and no edge, and when I remove the database calls, the login works fine. I just don't understand what the issue could be.
9 replies
DTDrizzle Team
•Created by Boby on 10/22/2024 in #help
I am getting an error when I defined the db
Maybe try this:
import { neon } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import * as schema from './schema';
const sql = neon(process.env.NEON_DATABASE_URL!);
const db = drizzle(sql, { schema });
export default db;
It is worked for me.11 replies
DTDrizzle Team
•Created by Ganbatte on 8/14/2024 in #help
Help Needed with Drizzlekit Migration Issue
Here's an image showing how it looked before:https://ibb.co/FYcxSG4
along with a snippet of the schema:
//Orders
export const orders = pgTable('orders', {
id: serial('id').primaryKey(),
userID: text('userID')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
total: real('total').notNull(),
status: text('status').notNull(),
receiptURL: text('receiptURL'),
paymentIntentID: text('paymentIntentID'),
created: timestamp('created').defaultNow().notNull(),
});
export const orderProduct = pgTable('orderProduct', {
id: serial('id').primaryKey(),
quantity: real('quantity').notNull(),
variantID: serial('variantID')
.notNull()
.references(() => productVariants.id, { onDelete: 'cascade' }),
productID: serial('productID')
.notNull()
.references(() => products.id, { onDelete: 'cascade' }),
orderID: serial('orderID')
.notNull()
.references(() => orders.id, { onDelete: 'cascade' }),
// created: timestamp('created').defaultNow().notNull(),
});
//Orders relations
export const orderRelations = relations(orders, ({ one, many }) => ({
user: one(users, {
fields: [orders.userID],
references: [users.id],
relationName: 'orders',
}),
orderProducts: many(orderProduct, {
relationName: 'orderProduct',
}),
}));
export const orderProductRelations = relations(orderProduct, ({ one }) => ({
orders: one(orders, {
fields: [orderProduct.orderID],
references: [orders.id],
relationName: 'orderProduct',
}),
product: one(products, {
fields: [orderProduct.productID],
references: [products.id],
relationName: 'products',
}),
variant: one(productVariants, {
fields: [orderProduct.variantID],
references: [productVariants.id],
relationName: 'productVariants',
}),
}));
2 replies
DTDrizzle Team
•Created by Ganbatte on 7/17/2024 in #help
How to Reference a Column Type in Drizzle
oh yes, Thank you so much!
4 replies
KPCKevin Powell - Community
•Created by Ganbatte on 12/20/2023 in #front-end
Difficulty with Autocompletion for SCSS Variables in Visual Studio Code
Thank you very much for the quick response. I'm really grateful for your help; it finally works, something I've looked into several times but never managed to find the answer to. Isn't '@import' an outdated feature that's not widely supported anymore? I see '@use' as the replacement in the documentation. However, as you mentioned, I've created a 'config' folder within 'styles' in Next.js and named it 'index.scss'.
_variables.scss
config/index.scss
global.scss
What are your thoughts on this? Thank you in advance for the assistance! Have a wonderful day! 🔥
8 replies