zerobyte/app/test/helpers/auth.ts
Nico 2ff6451f37
test: use better-auth built-in test plugin (#599)
test: use better-auth built-in test plugin

refactor: map auth errors server side

refactor: native trusted providers callback usage

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

## Release Notes

* **New Features**
  * Enhanced SSO authentication error messaging with specific guidance for different failure scenarios (account linking required, email verification needed, banned accounts, invite-only access).

* **Chores**
  * Updated authentication dependencies to version 1.5.0.

* **Tests**
  * Extended test coverage for SSO error code handling and authentication scenarios.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-03-01 15:10:50 +01:00

25 lines
673 B
TypeScript

import { auth } from "~/server/lib/auth";
export const COOKIE_PREFIX = "zerobyte";
export function getAuthHeaders(token: string): { Cookie: string } {
return {
Cookie: `${COOKIE_PREFIX}.session_token=${token}`,
};
}
export async function createTestSession() {
const ctx = await auth.$context;
const user = ctx.test.createUser();
await ctx.test.saveUser(user);
const { headers, session } = await ctx.test.login({ userId: user.id });
const organizationId = (session as { activeOrganizationId?: string }).activeOrganizationId ?? "";
return {
headers: Object.fromEntries(headers.entries()) as Record<string, string>,
session,
user,
organizationId,
};
}