How to use @accounts/client - 10 common examples

To help you get started, we’ve selected a few @accounts/client 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 / packages / apollo / src / index.ts View on Github external
console.log(
              `[GraphQL Accounts Error]: Message: ${message}, Location: ${locations}, Path: ${path}`
            )
          );
        }
        if (networkError) {
          console.log(`[Network error]: ${networkError}`);
        }
      }),
      new HttpLink({
        uri: options.uri,
      }),
    ]),
  });

  const client = new AccountsClient(
    options,
    new AccountsGraphQLClient({
      graphQLClient: apollo,
    })
  );

  let password;
  if (require.resolve('@accounts/client-password')) {
    const AccountsClientPassword = require('@accounts/client-password').AccountsClientPassword; // tslint:disable-line no-implicit-dependencies
    password = new AccountsClientPassword(client, options.password);
  }

  return {
    client,
    apollo,
    link: accountsLink(client),
github accounts-js / accounts / examples / react-graphql-typescript / src / utils / accounts.ts View on Github external
import { InMemoryCache } from 'apollo-cache-inmemory';

// This auth link will inject the token in the headers on every request you make using apollo client
const authLink = accountsLink(() => accountsClient);

const httpLink = new HttpLink({
  uri: 'http://localhost:4000/graphql',
});

const apolloClient = new ApolloClient({
  link: from([authLink, httpLink]),
  cache: new InMemoryCache(),
});

const accountsGraphQL = new GraphQLClient({ graphQLClient: apolloClient });
const accountsClient = new AccountsClient({}, accountsGraphQL);
const accountsPassword = new AccountsClientPassword(accountsClient);

export { accountsClient, accountsGraphQL, accountsPassword, apolloClient };
github accounts-js / accounts / examples / next-graphql-typescript / utils / accounts.ts View on Github external
import { CookieStorage } from 'cookie-storage';
import fetch from 'isomorphic-fetch';

const cookieStorage = new CookieStorage();
const link = new HttpLink({
  uri: 'http://localhost:4000/graphql',
  fetch,
});
const cache = new InMemoryCache();
const apolloClient = new ApolloClient({
  link,
  cache,
});

const accountsGraphQL = new GraphQLClient({ graphQLClient: apolloClient });
const accountsClient = new AccountsClient(
  {
    // We tell the accounts-js client to use cookieStorage to store the tokens
    tokenStorage: cookieStorage,
  },
  accountsGraphQL
);

const accountsPassword = new AccountsClientPassword(accountsClient);

export { accountsClient, accountsGraphQL, accountsPassword, apolloClient };
github accounts-js / accounts / packages / e2e / __tests__ / servers / server-graphql.ts View on Github external
);
    const { schema, context } = AccountsModule.forRoot({
      accountsServer: this.accountsServer,
    });

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

    const apolloClient = new ApolloClient({ uri: `http://localhost:${this.port}` });

    const accountsClientGraphQL = new AccountsGraphQLClient({
      graphQLClient: apolloClient,
    });
    this.accountsClient = new AccountsClient({}, accountsClientGraphQL);
    this.accountsClientPassword = new AccountsClientPassword(this.accountsClient);
    this.emails = [];
  }
github accounts-js / accounts / packages / e2e / __tests__ / servers / server-rest.ts View on Github external
}
    );

    /**
     * Setup express
     */
    this.app = express();
    this.app.use(bodyParser.json());
    this.app.use(bodyParser.urlencoded({ extended: true }));
    this.app.use(accountsExpress(this.accountsServer));

    const accountsRest = new RestClient({
      apiHost: `http://localhost:${this.port}`,
      rootPath: '/accounts',
    });
    this.accountsClient = new AccountsClient({}, accountsRest);
    this.accountsClientPassword = new AccountsClientPassword(this.accountsClient);
    this.emails = [];
  }
github accounts-js / accounts / examples / react-rest-typescript / src / accounts.ts View on Github external
import { AccountsClient } from '@accounts/client';
import { AccountsClientPassword } from '@accounts/client-password';
import { RestClient } from '@accounts/rest-client';

const accountsRest = new RestClient({
  apiHost: process.env.REACT_APP_API_URL!,
  rootPath: '/accounts',
});
const accountsClient = new AccountsClient({}, accountsRest);
const accountsPassword = new AccountsClientPassword(accountsClient);

export { accountsClient, accountsRest, accountsPassword };
github flyblackbird / apollo-accounts / client / index.js View on Github external
constructor(apolloClient, accountsClientOptions) {
    const accountsGraphQL = new GraphQLClient({ graphQLClient: apolloClient })
    const accountsClient = new AccountsClient(
      accountsClientOptions,
      accountsGraphQL
    )
    const accountsPassword = new AccountsClientPassword(accountsClient)

    this.accountsGraphQL = accountsGraphQL
    this.accountsClient = accountsClient
    this.accountsPassword = accountsPassword

    this.createUser = accountsPassword.createUser.bind(accountsPassword)
    this.login = accountsPassword.login.bind(accountsPassword)
    this.refreshSession = accountsClient.refreshSession.bind(accountsClient)
    this.logout = accountsClient.logout.bind(accountsClient)

    this.getUser = accountsGraphQL.getUser.bind(accountsGraphQL)
github birkir / prime / packages / prime-ui / src / utils / accounts.ts View on Github external
const withToken = setContext(() => {
  return {
    headers: {
      'x-prime-token': localStorage.getItem('accounts:accessToken'),
    },
  };
});

const client = new ApolloClient({
  link: concat(withToken, httpLink),
  cache: new InMemoryCache(),
});

const accountsGraphQL = new GraphQLClient({ graphQLClient: client });
const accountsClient = new AccountsClient({}, accountsGraphQL);
const accountsPassword = new AccountsClientPassword(accountsClient);

export { accountsClient, accountsGraphQL, accountsPassword };
github RocketChat / Rocket.Chat.PWA / src / app / shared / services / accounts-client.ts View on Github external
import { GraphQLClient } from '@accounts/graphql-client';
import { AccountsClient, config } from '@accounts/client';
import { userFieldsFragment } from '../../graphql/queries/user.fragment';
import { getApolloClient } from '../../graphql/client/apollo-client';
import { store } from '../common/store';

const client = getApolloClient();
const graphQLInterface = new GraphQLClient({
  graphQLClient: client,
  userFieldsFragment,
});

const accountsClient = new AccountsClient({
  tokenStorage: localStorage,
  reduxStoreKey: 'accounts',
  store,
  onSignedOutHook: () => null,
  onEnrollAccountHook: () => null,
  onResetPasswordHook: () => null,
  onVerifyEmailHook: () => null,
  onSignedInHook: () => null,
}, graphQLInterface);

export function getAccountsClient() {
  return accountsClient;
}

@accounts/client

Fullstack authentication and accounts-management

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Popular @accounts/client functions