N
Neon3mo ago
like-gold

RLS Authorized isn't working with custom JWT Token

I have built an app that using neon as a database along with Drizzle as the orm. My app used to work fine before but now I get a TLS error:
[Error: 58550000:error:0A00041A:SSL routines:ssl3_read_bytes:tlsv1 alert decode error:openssl\ssl\record\rec_layer_s3.c:1605:SSL alert number 50
]
[Error: 58550000:error:0A00041A:SSL routines:ssl3_read_bytes:tlsv1 alert decode error:openssl\ssl\record\rec_layer_s3.c:1605:SSL alert number 50
]
I have tried multiple approaches to find a clue: - I ensured drizzle wasn't the issue atleast without JWT. I can use neonclient with drizzle and it works with DATABASE_URL but when I add the token with the client it then gives the TLS error. This is my code below for reference:
"use server";

import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { auth } from "@/auth";

export interface SessionUserType {
access_token?: string;
id: string;
name: string;
email: string;
}

export async function db() {
const session = await auth();

let authToken: string;
if (!session) {
console.warn("No session found; using fallback token");
authToken = process.env.TEST_ACCESS_TOKEN!;
} else {
const user = session.user as SessionUserType;
authToken = user?.access_token ? `${user.access_token}` : "";
}

console.log("Retrieved token:", authToken);
if (!authToken) {
throw new Error("No token available");
}

const neonClient = neon(process.env.DATABASE_AUTHENTICATED_URL!, {
authToken: authToken});

return drizzle(neonClient);
}
"use server";

import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { auth } from "@/auth";

export interface SessionUserType {
access_token?: string;
id: string;
name: string;
email: string;
}

export async function db() {
const session = await auth();

let authToken: string;
if (!session) {
console.warn("No session found; using fallback token");
authToken = process.env.TEST_ACCESS_TOKEN!;
} else {
const user = session.user as SessionUserType;
authToken = user?.access_token ? `${user.access_token}` : "";
}

console.log("Retrieved token:", authToken);
if (!authToken) {
throw new Error("No token available");
}

const neonClient = neon(process.env.DATABASE_AUTHENTICATED_URL!, {
authToken: authToken});

return drizzle(neonClient);
}
- I downgraded Postgres from 17 to 15 to check if that was the issue. but it didn't fix it. - I then read in the document about the serverless driver from 1.0.0 was changing so I downgraded to 0.10.4 along with drizzle-orm from 0.44.1 to 0.39.1 but to no avail. - My app is hosted on vercel and thought maybe that was the issue. So I spun up a deno app in cloudflare which didn't work too. - Finally, I created a new neon project to test out if authenticated irl with token would work and still the issue presists.
5 Replies
like-gold
like-goldOP3mo ago
I have the same structure as this repo: https://github.com/neondatabase-labs/rls-demo-custom-jwt
GitHub
GitHub - neondatabase-labs/rls-demo-custom-jwt: A demo of Neon RLS ...
A demo of Neon RLS with custom generated JWTs. Contribute to neondatabase-labs/rls-demo-custom-jwt development by creating an account on GitHub.
plain-purple
plain-purple3mo ago
Can you DM me your project ID and I can take a look in the back end
like-gold
like-goldOP3mo ago
Sent! Hey @Conrad Ludgate I may have been lost in your dm. The error won't go away. How shall I proceed further? We really need to push an MVP with neon out. @mrl5 I saw the github issue you were attending to and I have the same issue. I can provide more details about it.
deep-jade
deep-jade2mo ago
you probably meant https://github.com/neondatabase/serverless/issues/167 it was resolved couple days after your message. I guess you're not experiencing issues anymore?
GitHub
Error connecting to database: ConnectionRefused: Unable to connect....
Hi team, I am experiencing this issue all of sudden. Previously it was working well. Error connecting to database: ConnectionRefused: Unable to connect. Is the computer able to access the url? This...
like-gold
like-goldOP2mo ago
Haha, I was the one who contacted you in that issue. Thanks again for looking into it : )

Did you find this page helpful?