(baseUrl: string, identity: Identity)
| 41 | // Better Auth email sign-in → session cookie (selfhost). The `origin` header is |
| 42 | // required: Better Auth rejects state-changing requests without one. |
| 43 | const signInHeaders = (baseUrl: string, identity: Identity) => |
| 44 | Effect.promise(async (): Promise<Record<string, string>> => { |
| 45 | const credentials = identity.credentials; |
| 46 | if (!credentials) throw new Error(`identity ${identity.label} has no headers or credentials`); |
| 47 | const response = await fetch(new URL("/api/auth/sign-in/email", baseUrl), { |
| 48 | method: "POST", |
| 49 | headers: { "content-type": "application/json", origin: new URL(baseUrl).origin }, |
| 50 | body: JSON.stringify(credentials), |
| 51 | redirect: "manual", |
| 52 | }); |
| 53 | const cookie = (response.headers.getSetCookie?.() ?? []).map((c) => c.split(";")[0]).join("; "); |
| 54 | if (!cookie) throw new Error(`api: sign-in set no cookie (${response.status})`); |
| 55 | return { cookie }; |
| 56 | }); |
no test coverage detected