fix #12: extract session token before dot (Better Auth signed cookie)
Better Auth cookie format is 'token.signature' but DB only stores the token portion. Split on '.' to extract the actual session token.
This commit is contained in:
@@ -30,7 +30,7 @@ export async function POST(request: Request) {
|
|||||||
.split(";")
|
.split(";")
|
||||||
.map((c) => c.trim())
|
.map((c) => c.trim())
|
||||||
.find((c) => c.startsWith("__Secure-better-auth.session_token=") || c.startsWith("better-auth.session_token="));
|
.find((c) => c.startsWith("__Secure-better-auth.session_token=") || c.startsWith("better-auth.session_token="));
|
||||||
const token = cookieMatch?.split("=")?.slice(1)?.join("=")?.trim();
|
const token = cookieMatch?.split("=")?.slice(1)?.join("=")?.trim().split(".")[0];
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return Response.json({ error: "Authentication required" }, { status: 401 });
|
return Response.json({ error: "Authentication required" }, { status: 401 });
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export async function GET(request: Request) {
|
|||||||
.split(";")
|
.split(";")
|
||||||
.map((c) => c.trim())
|
.map((c) => c.trim())
|
||||||
.find((c) => c.startsWith("__Secure-better-auth.session_token=") || c.startsWith("better-auth.session_token="));
|
.find((c) => c.startsWith("__Secure-better-auth.session_token=") || c.startsWith("better-auth.session_token="));
|
||||||
const token = cookieMatch?.split("=")?.slice(1)?.join("=")?.trim();
|
const token = cookieMatch?.split("=")?.slice(1)?.join("=")?.trim().split(".")[0];
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export async function GET() {
|
|||||||
.split(";")
|
.split(";")
|
||||||
.map((c) => c.trim())
|
.map((c) => c.trim())
|
||||||
.find((c) => c.startsWith("__Secure-better-auth.session_token=") || c.startsWith("better-auth.session_token="));
|
.find((c) => c.startsWith("__Secure-better-auth.session_token=") || c.startsWith("better-auth.session_token="));
|
||||||
const token = cookieMatch?.split("=")?.slice(1)?.join("=")?.trim();
|
const token = cookieMatch?.split("=")?.slice(1)?.join("=")?.trim().split(".")[0];
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user