How to use @accounts/database-manager - 4 common examples

To help you get started, we’ve selected a few @accounts/database-manager examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flyblackbird / apollo-accounts / server / index.js View on Github external
console.error('createApolloAccounts: db is a required parameter')
  }
  if (!givenOptions.tokenSecret) {
    console.log(
      'Warning: Must provide a tokenSecret (long random string) to createApolloAccounts()'
    )
  }

  const mongoStorage = new MongoDBInterface(db, {
    convertUserIdToMongoObjectId: false,
    convertSessionIdToMongoObjectId: false,
    idProvider,
    dateProvider
  })

  const dbManager = new DatabaseManager({
    sessionStorage: mongoStorage,
    userStorage: mongoStorage
  })

  const options = defaultsDeep(givenOptions, defaultOptions)

  const accountsServer = new AccountsServer(
    { db: dbManager, ...options },
    {
      password: new AccountsPassword()
    }
  )

  // full list of hooks:
  // https://github.com/accounts-js/accounts/blob/master/packages/server/src/utils/server-hooks.ts
  accountsServer.on('LoginSuccess', callOnLoginHooks)
github accounts-js / accounts / examples / graphql-server-typescript / src / index.ts View on Github external
const start = async () => {
  // Create database connection
  await mongoose.connect('mongodb://localhost:27017/accounts-js-graphql-example', {
    useNewUrlParser: true,
  });
  const mongoConn = mongoose.connection;

  // Build a storage for storing users
  const userStorage = new MongoDBInterface(mongoConn);
  // Create database manager (create user, find users, sessions etc) for accounts-js
  const accountsDb = new DatabaseManager({
    sessionStorage: userStorage,
    userStorage,
  });

  const accountsPassword = new AccountsPassword({
    // This option is called when a new user create an account
    // Inside we can apply our logic to validate the user fields
    validateNewUser: user => {
      // For example we can allow only some kind of emails
      if (user.email.endsWith('.xyz')) {
        throw new Error('Invalid email');
      }
      return user;
    },
  });
github accounts-js / accounts / packages / boost / src / index.ts View on Github external
const storage = await Object.keys(databasePackages).reduce(
    async (res, packageName: string): Promise => {
      const requiredPackage = requirePackage(packageName);
      if (requiredPackage) {
        return (databasePackages as any)[packageName](requiredPackage);
      }
      return res;
    },
    Promise.resolve([])
  );

  if (!storage) {
    throw new Error('A database package could not be loaded. Did you install one?');
  }

  options.db = new DatabaseManager({
    userStorage: storage,
    sessionStorage: storage,
  });

  const servicePackages = {
    ['@accounts/password']: async (requiredPackage: any): Promise => {
      const AccountsPassword = requiredPackage.default;
      return new AccountsPassword(get(options, ['services', 'password']));
    },
  };

  const services = await Object.keys(servicePackages).reduce(
    async (res, packageName: string): Promise => {
      const requiredPackage = requirePackage(packageName);
      if (requiredPackage) {
        const service = await (servicePackages as any)[packageName](requiredPackage);

@accounts/database-manager

Accounts Database Manager, allow the use of separate databases for session and user

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Popular @accounts/database-manager functions