N
Neon8h ago
absent-sapphire

RLS authorization issue with authenticated role and drizzle

Hi, I tried the guide for using rls with drizzle: https://neon.com/docs/guides/rls-drizzle, but it's not working for me.
import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { users } from "@/db/schema";

const accessToken = <access_token>;

const createAuthenticatedDb = () => {
const connectionString = <authenticated_db_connection_string>;

if (!connectionString) {
throw new Error("Database connection string is not set");
}

const sql = neon(connectionString);

return drizzle(sql);
};

const db = createAuthenticatedDb();

const run = async () => {
const result = await db.$withAuth(accessToken).select().from(users);
console.log(result);
};
import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { users } from "@/db/schema";

const accessToken = <access_token>;

const createAuthenticatedDb = () => {
const connectionString = <authenticated_db_connection_string>;

if (!connectionString) {
throw new Error("Database connection string is not set");
}

const sql = neon(connectionString);

return drizzle(sql);
};

const db = createAuthenticatedDb();

const run = async () => {
const result = await db.$withAuth(accessToken).select().from(users);
console.log(result);
};
I have verified that the access token is verifiable with the JKWS URL that I have setup on neon. However, upon running this, I got:
NeonDbError: This JWT does not have authorization to access this resource.
NeonDbError: This JWT does not have authorization to access this resource.
Is there an issue I should be aware of? Thanks.
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?