This commit is contained in:
Luke Vella 2025-02-12 16:20:31 +07:00
parent 3c959eba2b
commit 30f6d0d447
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C
4 changed files with 13 additions and 9 deletions

View file

@ -1,5 +1,6 @@
PORT=3002 PORT=3002
NEXT_PUBLIC_BASE_URL=http://localhost:3002 NEXT_PUBLIC_BASE_URL=http://localhost:3002
AUTH_URL=http://localhost:3002
SECRET_PASSWORD=abcdef1234567890abcdef1234567890 SECRET_PASSWORD=abcdef1234567890abcdef1234567890
DATABASE_URL=postgres://postgres:postgres@localhost:5450/rallly DATABASE_URL=postgres://postgres:postgres@localhost:5450/rallly
SUPPORT_EMAIL=support@rallly.co SUPPORT_EMAIL=support@rallly.co

View file

@ -60,6 +60,7 @@ export function withAuthMigration(
res.cookies.set(newCookieName, encodedCookie, { res.cookies.set(newCookieName, encodedCookie, {
httpOnly: true, httpOnly: true,
secure: isSecureCookie, secure: isSecureCookie,
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
sameSite: "lax", sameSite: "lax",
path: "/", path: "/",
}); });

View file

@ -1,5 +1,4 @@
import hkdf from "@panva/hkdf"; import hkdf from "@panva/hkdf";
import { nanoid } from "@rallly/utils/nanoid";
import { EncryptJWT } from "jose"; import { EncryptJWT } from "jose";
import type { JWT } from "next-auth/jwt"; import type { JWT } from "next-auth/jwt";
@ -32,6 +31,6 @@ export async function encode(params: JWTEncodeParams) {
.setProtectedHeader({ alg: "dir", enc: "A256GCM" }) .setProtectedHeader({ alg: "dir", enc: "A256GCM" })
.setIssuedAt() .setIssuedAt()
.setExpirationTime(now() + maxAge) .setExpirationTime(now() + maxAge)
.setJti(nanoid()) .setJti("some-random-id")
.encrypt(encryptionSecret); .encrypt(encryptionSecret);
} }

View file

@ -1,6 +1,5 @@
import { expect, test } from "@playwright/test"; import { expect, test } from "@playwright/test";
import { prisma } from "@rallly/database"; import { prisma } from "@rallly/database";
import { nanoid } from "@rallly/utils/nanoid";
import { encode } from "./helpers/next-auth-v4"; import { encode } from "./helpers/next-auth-v4";
@ -12,8 +11,8 @@ test.describe.serial(() => {
data: { data: {
id: "legacy-guest-poll", id: "legacy-guest-poll",
title: "Test Poll", title: "Test Poll",
adminUrlId: nanoid(), adminUrlId: "admin-url-id",
participantUrlId: nanoid(), participantUrlId: "participant-url-id",
guestId: legacyGuestId, guestId: legacyGuestId,
}, },
}); });
@ -28,7 +27,7 @@ test.describe.serial(() => {
test("should see poll on login page", async ({ page }) => { test("should see poll on login page", async ({ page }) => {
const context = page.context(); const context = page.context();
const token = await encode({ const legacyToken = await encode({
token: { token: {
sub: legacyGuestId, sub: legacyGuestId,
}, },
@ -39,15 +38,19 @@ test.describe.serial(() => {
await context.addCookies([ await context.addCookies([
{ {
name: "next-auth.session-token", name: "next-auth.session-token",
value: token, value: legacyToken,
httpOnly: true, httpOnly: true,
expires: Date.now() / 1000 + 60 * 60 * 24 * 7,
secure: false, secure: false,
sameSite: "Lax", sameSite: "Lax",
path: "/",
domain: "localhost", domain: "localhost",
path: "/",
}, },
]); ]);
await page.goto("/login");
await page.goto("/");
// Check if the poll title exists in the page content
await expect(page.getByText("Test Poll")).toBeVisible(); await expect(page.getByText("Test Poll")).toBeVisible();
}); });
}); });