fix: use __Secure- cookie prefix for HTTPS session auth
This commit is contained in:
parent
a39b68e866
commit
72ff35b333
3 changed files with 19 additions and 3 deletions
|
|
@ -43,11 +43,21 @@ export function getTestAuthContext(): TestAuthContext {
|
|||
|
||||
/**
|
||||
* Create a fetch function with session cookie authentication
|
||||
*
|
||||
* Note: better-auth uses different cookie names for HTTP vs HTTPS:
|
||||
* - HTTP: better-auth.session_token
|
||||
* - HTTPS: __Secure-better-auth.session_token
|
||||
*
|
||||
* We send both to ensure compatibility.
|
||||
*/
|
||||
export function createSessionFetch(sessionToken: string): typeof fetch {
|
||||
return (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const headers = new Headers(init?.headers);
|
||||
headers.set('Cookie', `better-auth.session_token=${sessionToken}`);
|
||||
// Send both cookie formats to work with both HTTP and HTTPS
|
||||
headers.set(
|
||||
'Cookie',
|
||||
`better-auth.session_token=${sessionToken}; __Secure-better-auth.session_token=${sessionToken}`
|
||||
);
|
||||
|
||||
return fetch(input, {
|
||||
...init,
|
||||
|
|
|
|||
|
|
@ -64,7 +64,10 @@ export function createAgentFactory(api: ApiClient, tracker: TestDataTracker) {
|
|||
});
|
||||
|
||||
if (!result.ok) {
|
||||
throw new Error(`Failed to create agent: ${(result as { error: string }).error}`);
|
||||
const errorResult = result as { error: string; status: number };
|
||||
throw new Error(
|
||||
`Failed to create agent: ${errorResult.error} (status: ${errorResult.status})`
|
||||
);
|
||||
}
|
||||
|
||||
const agent = result.data.data;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,10 @@ export function createCollectionFactory(api: ApiClient, tracker: TestDataTracker
|
|||
);
|
||||
|
||||
if (!result.ok) {
|
||||
throw new Error(`Failed to create collection: ${(result as { error: string }).error}`);
|
||||
const errorResult = result as { error: string; status: number };
|
||||
throw new Error(
|
||||
`Failed to create collection: ${errorResult.error} (status: ${errorResult.status})`
|
||||
);
|
||||
}
|
||||
|
||||
const collection = result.data.data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue