Application error when session is expired

No description
8 Replies
bekacru
bekacru9mo ago
this is probably caused by somewhere in your app you're throwing error if session isn't available or something
dun
dunOP9mo ago
{!session ? (
<Button asChild>
<Link href="/login">Login</Link>
</Button>
) : (
<DropdownMenu>
{!session ? (
<Button asChild>
<Link href="/login">Login</Link>
</Button>
) : (
<DropdownMenu>
this ?
bekacru
bekacru9mo ago
it's saying server side exception happend. check what's the error on the server.
dun
dunOP9mo ago
[Error [BetterCallAPIError]: API Error: INTERNAL_SERVER_ERROR Failed to get session] {
2024-12-20T19:20:15.692151906Z status: 'INTERNAL_SERVER_ERROR',
2024-12-20T19:20:15.692158048Z headers: [HeadersList],
2024-12-20T19:20:15.692161625Z body: [Object],
2024-12-20T19:20:15.692165201Z digest: '2603914421',
2024-12-20T19:20:15.692168317Z [cause]: [Object]
2024-12-20T19:20:15.692171403Z }
[Error [BetterCallAPIError]: API Error: INTERNAL_SERVER_ERROR Failed to get session] {
2024-12-20T19:20:15.692151906Z status: 'INTERNAL_SERVER_ERROR',
2024-12-20T19:20:15.692158048Z headers: [HeadersList],
2024-12-20T19:20:15.692161625Z body: [Object],
2024-12-20T19:20:15.692165201Z digest: '2603914421',
2024-12-20T19:20:15.692168317Z [cause]: [Object]
2024-12-20T19:20:15.692171403Z }
is it the middleware?
const { data: session } = await betterFetch<Session>(
"/api/auth/get-session",
{
baseURL: env.NEXT_PUBLIC_APP_URL,
headers: {
cookie: cookies || "",
},
}
);

const endTime = Date.now();
const duration = endTime - startTime;

console.log(`____Get Session Time: ${duration}ms`);
console.log(cookies);

if (isAuthRoute) { //login and signup
if (session) {
return NextResponse.redirect(new URL(AUTHENTICATED_URL, request.url));
}
return NextResponse.next();
}
const { data: session } = await betterFetch<Session>(
"/api/auth/get-session",
{
baseURL: env.NEXT_PUBLIC_APP_URL,
headers: {
cookie: cookies || "",
},
}
);

const endTime = Date.now();
const duration = endTime - startTime;

console.log(`____Get Session Time: ${duration}ms`);
console.log(cookies);

if (isAuthRoute) { //login and signup
if (session) {
return NextResponse.redirect(new URL(AUTHENTICATED_URL, request.url));
}
return NextResponse.next();
}
is it because the session is exist but expired?
bekacru
bekacru9mo ago
sorry for late resposne wanted to get out the release. I'm gonna take a look tomorrow
dun
dunOP9mo ago
hello, any solution for this issue?
bekacru
bekacru9mo ago
https://github.com/laduniestu/better-next/blob/main/src/app/(public)/_components/header.tsx my guess is this file here getSession is throwing error. Try to catch that and see if that's the problem
GitHub
better-next/src/app/(public)/_components/header.tsx at main · ladun...
Nextjs starterkit using Better Auth. Contribute to laduniestu/better-next development by creating an account on GitHub.
bekacru
bekacru9mo ago
in genreal the issue is somwhere in your server component an error is being thrown.

Did you find this page helpful?