Cookies won't set on mac but working on windows
Unanswered
Savannah posted this in #help-forum
SavannahOP
Hey guys, anyone have an idea on why my cookies won't set on mac but working on windows ? Idk if im doing something wrong tbh
lib/session.ts :
lib/session.ts :
import {jwtVerify, SignJWT} from "jose";
import {cookies} from "next/headers";
const secretKey = process.env.NEXTAUTH_SECRET
const encodedKey = new TextEncoder().encode(secretKey)
async function encrypt(payload: any) {
return new SignJWT(payload)
.setProtectedHeader({alg: 'HS256'})
.setIssuedAt()
.setExpirationTime('7d')
.sign(encodedKey)
}
async function decrypt(session: string | undefined = '') {
try {
const {payload} = await jwtVerify(session, encodedKey, {
algorithms: ['HS256']
})
return payload
} catch (error) {
console.log('Failed to verify session')
}
}
export async function createSession(userId: string) {
const expiresAt = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
const session = await encrypt({userId, expiresAt})
cookies().set('session', session, {
httpOnly: true,
secure: true,
expires: expiresAt,
path: '/'
})
console.log('Session created', session)
}
export async function getSession() {
const cookie: string | undefined = cookies().get('session')?.value;
return await decrypt(cookie);
}
export async function deleteSession() {
cookies().delete('session');
}