MongoDB provider for AdonisJS 5.
This provider requires AdonisJS v5 and won't work with AdonisJS v4.
We recommend using MongoDB >=5.0. Earlier versions are not tested.
npm i @zakodium/adonis-mongodb
node ace configure @zakodium/adonis-mongodb
Adonis MongoDB can be used to authenticate users with the @adonisjs/auth
addon.
To enable it, edit the following files:
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'>;
};
}
}
import { AuthConfig } from '@ioc:Adonis/Addons/Auth';
const authConfig: AuthConfig = {
guard: 'web',
guards: {
web: {
driver: 'session',
provider: {
driver: 'mongodb-model',
},
},
},
};
export default authConfig;
To run tests locally:
docker-compose up -d
node reset-dev.mjs
npm test
docker-compose down