joseph013318
BABetter Auth
•Created by joseph013318 on 3/3/2025 in #help
Caching is not utilized, I have setup cookieCache true, still no cache
In my next.js app using prisma postgres for user management database, session storage and all. How do I cache the data in prisma?
Getting this
GET http://localhost:3000/api/auth/get-session 200 in 3776ms (cache skip)
│ │ Cache skipped reason: (auto no cache)
I have setup cookieCache true, still no cache. Every time refresh It keeps hitting the prisma database
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day (every 1 day the session expiration is updated)
cookieCache: {
enabled: true,
maxAge: 5 * 60 // Cache duration in seconds
}
},
2 replies
BABetter Auth
•Created by joseph013318 on 3/1/2025 in #help
While deploying - A Node.js API is used (process.exit at line: 1451) which is not supported in..
While deploying my next.js app on vercel it's giving this error
./node_modules/better-auth/dist/chunk-62MWLLEG.js
A Node.js API is used (process.exit at line: 1451) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime
11 replies
BABetter Auth
•Created by joseph013318 on 2/27/2025 in #help
Prisma database with Prisma orm showing Cache skipped reason: (auto no cache)
Whenever I refresh the website it shows this - GET http://localhost:3000/api/auth/get-session 200 in 85ms (cache skip)
auth.js
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql"
}),
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day (every 1 day the session expiration is updated)
cookieCache: {
enabled: true,
maxAge: 5 * 60 // Cache duration in seconds
}
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
},
},
})
5 replies
BABetter Auth
•Created by joseph013318 on 2/25/2025 in #help
Session cookies issue
In my next.js app console also it's showing session as
null
I wantto protect dashboard
page with middleware.js
. I see I can easily navigate to dashboard
page, on console.log of sessionCookie
from getSessionCookie
it's showing sessionCookie id
I also check devtools about the same Dev tools -> Application -> Cookies -> localhost:3000 -> better-auth
with expiry set to March 3, 2025 but showing session as null on console. The middlware is working fine on incognito mode. Please tell what am I doing wrong 😭
This my code
middleware.js
import { NextResponse } from "next/server";
import { getSessionCookie } from "better-auth";
export async function middleware(request) {
const sessionCookie = getSessionCookie(request);
console.log("sessionCookie", sessionCookie);
// Optionally pass config as the second argument if cookie name or prefix is customized.
if (!sessionCookie) {
return NextResponse.redirect(new URL("/", request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/dashboard"], // Specify the routes the middleware applies to
};
lib/auth.js
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "postgresql"
}),
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days
updateAge: 60 * 60 * 24, // 1 day (every 1 day the session expiration is updated)
cookieCache: {
enabled: true,
maxAge: 5 * 60 // Cache duration in seconds
}
},
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
},
},
})
2 replies
BABetter Auth
•Created by joseph013318 on 2/24/2025 in #help
How to integrate better-auth with cloudfare D1 database?
How to integrate better-auth with cloudfare D1 database?
7 replies