Package Exports
- @zakodium/adonis-mongodb
- @zakodium/adonis-mongodb/lib/providers/MongodbProvider.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@zakodium/adonis-mongodb) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Adonis MongoDB
MongoDB provider for AdonisJS 5.
Maintained by Zakodium
⚠️ This module is unstable and in active development. Use at your own risk. |
---|
Prerequisites
This provider requires AdonisJS v5 and won't work with AdonisJS v4.
We recommend using MongoDB >=5.0. Earlier versions are not tested.
Installation
npm i @zakodium/adonis-mongodb
node ace configure @zakodium/adonis-mongodb
Documentation
Using with the authentication provider
Adonis MongoDB can be used to authenticate users with the @adonisjs/auth
addon.
To enable it, edit the following files:
contracts/auth.ts
Example of a configuration with the session guard:
import {
MongodbModelAuthProviderContract,
MongodbModelAuthProviderConfig,
} from '@ioc:Zakodium/Mongodb/Odm';
import User from 'App/Models/User';
declare module '@ioc:Adonis/Addons/Auth' {
interface ProvidersList {
user: {
implementation: MongodbModelAuthProviderContract<typeof User>;
config: MongodbModelAuthProviderConfig<typeof User>;
};
}
interface GuardsList {
web: {
implementation: SessionGuardContract<'user', 'web'>;
config: SessionGuardConfig<'user'>;
};
}
}
config/auth.ts
import { AuthConfig } from '@ioc:Adonis/Addons/Auth';
const authConfig: AuthConfig = {
guard: 'web',
guards: {
web: {
driver: 'session',
provider: {
driver: 'mongodb-model',
},
},
},
};
export default authConfig;
Development
To run tests locally:
docker compose up -d
node reset-dev.mjs
npm test
docker compose down