How to use the @accounts/server.AccountsServer function in @accounts/server

To help you get started, we’ve selected a few @accounts/server 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 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 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
github accounts-js / accounts / examples / rest-express-typescript / src / index.ts View on Github external
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',
  },
  {
    password: accountsPassword,
  }
);

accountsServer.on(ServerHooks.ValidateLogin, ({ user }) => {
  // This hook is called every time a user try to login.
  // You can use it to only allow users with verified email to login.
  // If you throw an error here it will be returned to the client.
});

app.use(accountsExpress(accountsServer));
github accounts-js / accounts / examples / graphql-server-typescript / src / index.ts View on Github external
});

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

  // Creates resolvers, type definitions, and schema directives used by accounts-js
  const accountsGraphQL = AccountsModule.forRoot({
    accountsServer,
  });

  const typeDefs = gql`
    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',
            text: (user: User, url: string) => convertUrlToToken(url),
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',
            text: (user: User, url: string) => convertUrlToToken(url),
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);
        }
      },
    },
    { password }
  );

  const accounts = AccountsModule.forRoot({
    accountsServer,
    headerName: 'x-prime-token',
github accounts-js / accounts / packages / boost / src / index.ts View on Github external
constructor(options: AccountsBoostOptions, services: { [key: string]: AuthenticationService }) {
    this.accountsServer = new AccountsServer(options, services);
    this.options = options;
    this.accountsGraphQL = AccountsModule.forRoot({
      accountsServer: this.accountsServer,
    });

    const { schema, context } = this.accountsGraphQL;

    this.apolloServer = new ApolloServer({
      schema,
      context,
    });
  }