Nextjs middleware not working

In this i am using the getSessionCookies() but the sessionCookie returns as null i am using the cookiePrefix also my session also getting from useSession i checked the cookies in the network also after the session checking it is also there my frontend is next js in local enviornment and the backend is in elysia js in deployed version do any know how to fix this
No description
No description
11 Replies
bekacru
bekacru3w ago
are you on latest?
shabiii
shabiiiOP3w ago
yes what do u know mean by vanilla client sir ? can u please explain which way i should use should i use getSessionCookie or authClient.getSession ? @bekacru
Shyam Verma
Shyam Verma3w ago
You can use package @better-fetch/fetch for getting session in middleware like this:
ts
const { data: session } = await betterFetch<Session>("/api/auth/get-session", {
baseURL: process.env.BETTER_AUTH_URL,
headers: { cookie: request.headers.get("cookie") || "" },
});
ts
const { data: session } = await betterFetch<Session>("/api/auth/get-session", {
baseURL: process.env.BETTER_AUTH_URL,
headers: { cookie: request.headers.get("cookie") || "" },
});
shabiii
shabiiiOP3w ago
@Shyam Verma
Shyam Verma
Shyam Verma3w ago
??
shabiii
shabiiiOP3w ago
should i change the cookie to my cookie name ?
Shyam Verma
Shyam Verma3w ago
what's the need of this. use defaults names
shabiii
shabiiiOP3w ago
if i use default name would it work?
Shyam Verma
Shyam Verma3w ago
Yes, definetly
shabiii
shabiiiOP3w ago
i removed the prefix still not worked
KiNFiSH
KiNFiSH3w ago
@shabiii send us your auth config for more clarify

Did you find this page helpful?