@mchegdali/better-auth-cosmosdb-adapter
v1.0.12
Published
CosmosDB database adapter for Better-Auth
Maintainers
Readme
Better Auth CosmosDB Adapter
Installation
With npm:
npm install better-auth @mchegdali/better-auth-cosmosdb-adapterWith pnpm:
pnpm add better-auth @mchegdali/better-auth-cosmosdb-adapterUsage
import { betterAuth } from "better-auth"
import { cosmosdbAdapter } from "@mchegdali/better-auth-cosmosdb-adapter";
const cosmosClient = new CosmosClient({ endpoint: "https://...", key: "..." });
const db = cosmosClient.database("my-db");
const containers = {
"container-1": db.container("container-1"),
"container-2": db.container("container-2"),
// ...
};
export const auth = betterAuth({
database: cosmosdbAdapter(containers, {
usePlural: true, // defaults to false
}),
});Testing
To run the tests, you need to have a CosmosDB instance running. We provide a Docker Compose file to help you get started which will start a CosmosDB Emulator instance.
- Clone the repository
git clone [email protected]:mchegdali/better-auth-cosmosdb-adapter.git- Navigate to the project directory
cd better-auth-cosmosdb-adapter- Set the required environment variables in a
.envfile.
If you are using CosmosDB Emulator, you can copy the .env.example file to .env and you are good to go.
cp .env.example .env- (Optional) If you want to run the tests against a CosmosDB instance, you can start the CosmosDB Emulator instance by running the following command:
docker compose up -d- Run the tests
# With npm
npm run test
# With pnpm
pnpm testTroubleshooting
If you are running the tests against a CosmosDB instance, you might encounter the following error:
cosmosdb-emulator | Error: The evaluation period has expired.
cosmosdb-emulator | ./cosmosdb-emulator: ERROR: PAL initialization failed. Error: 104
cosmosdb-emulator |
cosmosdb-emulator exited with code 1In this case, you need to pull the latest image from the CosmosDB Emulator repository and restart the container.
docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
docker compose up -dLicense
GNU General Public License v3.0
