Highlighted
Highlighted
BABetter Auth
Created by Highlighted on 2/23/2025 in #help
Better-auth and e2e tests
Hello, So I've encountered a difficulty creating fake users for e2e testing in playwright. I dont know how to generate fake token to add to the cookies. I've inspected the valid cookie with an account logged in normally and it seems like its just a session token + "." + some string in the end , ex: 123abc.123abc, but I have no idea how to generate that string. I would guess that its based on the secret. Thats what I've tried:
export async function loginAsTestUser(
context: BrowserContext,
) {
const email = `test-user-${crypto.randomUUID()}@example.com`;
const { data, error } = await authClient.signUp.email({
email: email,
password: "password1234",
name: "test",
image: "https://example.com/image.png",
});
if (!data?.token) {
throw new Error("Failed to create test user");
}
await context.addCookies([
{
name: "better-auth.session_token",
value: data.token,
domain: "localhost",
path: "/",
httpOnly: true,
sameSite: "Lax",
expires: -1,
}
]);
}
export async function loginAsTestUser(
context: BrowserContext,
) {
const email = `test-user-${crypto.randomUUID()}@example.com`;
const { data, error } = await authClient.signUp.email({
email: email,
password: "password1234",
name: "test",
image: "https://example.com/image.png",
});
if (!data?.token) {
throw new Error("Failed to create test user");
}
await context.addCookies([
{
name: "better-auth.session_token",
value: data.token,
domain: "localhost",
path: "/",
httpOnly: true,
sameSite: "Lax",
expires: -1,
}
]);
}
I've also searched the docs for some examples or maybe methods to generate it, but no luck. Anyone knows what to do?
7 replies