How to use @accounts/password - 9 common examples

To help you get started, we’ve selected a few @accounts/password 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 ardatan / graphql-modules-accountsjs-boilerplate / server / src / index.ts View on Github external
async function main() {
    const mongoClient = await MongoClient.connect(MONGO_URI, {
        useNewUrlParser: true,
        native_parser: true
    });
    const db = mongoClient.db();
    // Create accounts server that holds a lower level of all accounts operations
    const accountsServer = new AccountsServer(
        {
            db: new AccountsMongoDB(db),
            tokenSecret: TOKEN_SECRET
        },
        {
            password: new AccountsPassword(),
        }
    );
    const { schema, context } = AppModule.forRoot({
        accountsServer,
        db
    });
    const apolloServer = new ApolloServer({
        schema,
        context,
        introspection: true
    });
    const { url } = await apolloServer.listen(PORT);
    console.log(`Server listening: ${url}`);
}
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;
    },
  });

  // Create accounts server that holds a lower level of all accounts operations
  const accountsServer = new AccountsServer(
    { db: accountsDb, tokenSecret: 'secret' },
    {
      password: accountsPassword,
github flyblackbird / apollo-accounts / server / index.js View on Github external
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)
  accountsServer.on('CreateUserSuccess', callOnCreateUserHooks)

  return createAccountsGraphQL(accountsServer, { extend: true })
}
github accounts-js / accounts / examples / rest-express-typescript / src / index.ts View on Github external
import * as cors from 'cors';
import * as mongoose from 'mongoose';
import { AccountsServer, ServerHooks } from '@accounts/server';
import { AccountsPassword } from '@accounts/password';
import accountsExpress, { userLoader } from '@accounts/rest-express';
import MongoDBInterface from '@accounts/mongo';

mongoose.connect('mongodb://localhost:27017/accounts-js-rest-example', { useNewUrlParser: true });
const db = mongoose.connection;

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());

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;
  },
});

const accountsServer = new AccountsServer(
  {
    db: new MongoDBInterface(db),
    tokenSecret: 'secret',
  },
github accounts-js / accounts / examples / graphql-server-typeorm-postgres / src / index.ts View on Github external
export const createAccounts = async () => {
  const connection = await connect(process.env.DATABASE_URL);
  // Like, fix this man!
  const tokenSecret = 'process.env.ACCOUNTS_SECRET' || 'change this in .env';
  const db = new AccountsTypeorm({ connection, cache: 1000 });
  const password = new AccountsPassword();
  const accountsServer = new AccountsServer(
    {
      db,
      tokenSecret,
      siteUrl: 'http://localhost:3000',
    },
    { password }
  );
  // Creates resolvers, type definitions, and schema directives used by accounts-js
  const accountsGraphQL = AccountsModule.forRoot({
    accountsServer,
  });

  const typeDefs = `
type PrivateType @auth {
field: String
github accounts-js / accounts / packages / e2e / __tests__ / servers / server-rest.ts View on Github external
constructor() {
    this.databaseTest = new DatabaseTest();
    this.accountsDatabase = this.databaseTest.accountsDatabase;
    this.accountsPassword = new AccountsPassword();
    this.accountsServer = new AccountsServer(
      {
        db: this.accountsDatabase,
        tokenSecret: 'test',
        emailTemplates: {
          from: 'accounts-js ',
          verifyEmail: {
            subject: () => 'Verify your account email',
            text: (user: User, url: string) => convertUrlToToken(url),
          },
          resetPassword: {
            subject: () => 'Reset your password',
            text: (user: User, url: string) => convertUrlToToken(url),
          },
          enrollAccount: {
            subject: () => 'Set your password',
github accounts-js / accounts / packages / e2e / __tests__ / servers / server-graphql.ts View on Github external
constructor() {
    this.databaseTest = new DatabaseTest();
    this.accountsDatabase = this.databaseTest.accountsDatabase;
    this.accountsPassword = new AccountsPassword();
    this.accountsServer = new AccountsServer(
      {
        db: this.accountsDatabase,
        tokenSecret: 'test',
        emailTemplates: {
          from: 'accounts-js ',
          verifyEmail: {
            subject: () => 'Verify your account email',
            text: (user: User, url: string) => convertUrlToToken(url),
          },
          resetPassword: {
            subject: () => 'Reset your password',
            text: (user: User, url: string) => convertUrlToToken(url),
          },
          enrollAccount: {
            subject: () => 'Set your password',
github birkir / prime / packages / prime-core / src / modules / accounts / index.ts View on Github external
export const createAccounts = async (connection: Connection) => {
  const tokenSecret = ACCOUNTS_SECRET || 'not very secret secret';
  const db = new AccountsTypeorm({
    connection,
    cache: 1000,
  });

  const password = new AccountsPassword({
    twoFactor: {
      appName: 'Prime',
    },
  });

  const accountsServer = new AccountsServer(
    {
      db,
      tokenSecret,
      siteUrl: CORE_URL,
      sendMail(mail) {
        if (mailgun) {
          return mailgun.messages().send(mail);
        }
      },
    },

@accounts/password

[![npm](https://img.shields.io/npm/v/@accounts/password)](https://www.npmjs.com/package/@accounts/password) [![npm downloads](https://img.shields.io/npm/dm/@accounts/password)](https://www.npmjs.com/package/@accounts/password) [![codecov](https://img.shie

MIT
Latest version published 2 years ago

Package Health Score

43 / 100
Full package analysis

Popular @accounts/password functions

Similar packages