Skip to content

ValentinForks/adonis-mongodb

 
 

Repository files navigation

Adonis MongoDB

NPM version build status npm download

MongoDB provider for AdonisJS 5.

⚠️ This module is unstable and in active development. Use at your own risk.

Prerequisites

This provider requires Adonis v5 preview and won't work with Adonis v4.

We recommend using mongodb 4.4, because creation of collections and indices in migrations will be transactional and will be properly rolled back in case of error.

If you use a version < 4.4, you might run into issues with partially applied migrations.

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:Mongodb/Model';

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',
  list: {
    web: {
      driver: 'session',
      provider: {
        driver: 'mongodb-model',
      },
    },
  },
};

export default authConfig;

Tests

To run tests locally:

docker-compose up -d
node reset-dev.js
npm test
docker-compose down

License

MIT

About

MongoDB provider for AdonisJS 5

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 99.2%
  • JavaScript 0.8%