How to get cookie from next-auth ?
Answered
Scaly-naped Pigeon posted this in #help-forum
Scaly-naped PigeonOP
I am using elysiajs ( bunjs ) with nextjs but i want to get the session data but i always get payload false , why this happens , i already received the cookie into backend ( elysiajs ) but pay load is false , why ?
here is backend config
here is backend config
import { jwt } from '@elysiajs/jwt';
const app = new Elysia({ serve: { idleTimeout: 120 }})
.use(cors({
origin: ['http://localhost:3000'],
methods: ['GET', 'POST', 'PUT', 'DELETE'],
credentials: true
}))
.use(jwt({ name: 'jwt', secret: process.env.JWT_SECRET as string }))
.derive(async ({ cookie, request, jwt }) => {
const sessionToken = cookie['next-auth.session-token']?.value;
if (!sessionToken) {
return { user: null, session: null };
}
const payload = await jwt.verify(sessionToken);
console.log('payload ',payload)
if (!payload) {
return { user: null, session: null };
}
return {
session : { ...payload }
}})
Answered by American black bear
its not safe what i would do is moving next auth on elysia
6 Replies
American black bear
@Scaly-naped Pigeon are they both running on same port?
if no, auth cookies are httpOnly which means on localhost:3000 can read it
if no, auth cookies are httpOnly which means on localhost:3000 can read it
@American black bear <@1031275449294258287> are they both running on same port?
if no, auth cookies are httpOnly which means on localhost:3000 can read it
Scaly-naped PigeonOP
They are on different port frontend next Auth on 3000 backend on port 3001
Should I remove httpOnly and it would work ?
@Scaly-naped Pigeon Should I remove httpOnly and it would work ?
American black bear
its not safe what i would do is moving next auth on elysia
Answer
American black bear
and set cookies from elysia
Scaly-naped PigeonOP
I see , will try to do that , thanks for helping 🙏