npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apollo-accounts-password-client

v0.3.0-beta.26

Published

Fullstack accounts for Apollo: client side

Downloads

4

Readme

Apollo Accounts Password—Client npm version

Client side of Apollo Accounts Password, a full-stack JS accounts system for Apollo and MongoDB.

Usage

npm install apollo-accounts-password-client

import ApolloAccounts from 'apollo-accounts-password-client'
import ApolloClient from 'apollo-boost'

const apolloClient = new ApolloClient({
  uri: 'http://localhost:4000/graphql'
})

const Accounts = new ApolloAccounts(apolloClient)

Accounts.login({
  user: {
    email: '[email protected]'
  },
  password: 'foo'
})

(You'll also need to set up a server at localhost:4000/graphql that uses apollo-accounts-password-server.)

Demo

See flyblackbird/apollo-accounts

API

Below we list all the methods of ApolloAccounts. Most methods return a promise that resolves when the response is received from the server. If you need other methods that are supported by accounts-js, you can access them through:

Constructor

new ApolloAccounts(apolloClientInstance, accountsClientOptions)

Usually accountsClientOptions is left out, unless you're in React Native:

import { AsyncStorage } from 'react-native'

const Accounts = new ApolloAccounts(apolloClient, {
  tokenStorage: AsyncStorage
})

createUser

createUser({ email, password })
createUser({ username, password })

Argument may contain a profile property object with arbitrary data.

createUser() does not automatically log the user in.

login

login(loginInfo)

  • loginInfo:
    • user an object of the form { email: '[email protected]' } or { username: 'loren' }
    • password
    • code if you're using 2fa
Accounts.login({ password: 'foo', user: { email: '[email protected]' } })

refreshSession

const { accessToken, refreshToken } = Accounts.refreshSession()

Gets the login tokens from LocalStorage, or if the accessToken is expired, refreshes it (i.e. gets a new accessToken from the server using the refreshToken).

If it returns null, either:

  • The refreshToken is expired, and the user must login again.
  • There are no tokens, either because no one has logged in from this client, or they've cleared their LocalStorage.

If you'd like to be able to determine who last logged in to a particular client on page load, you can, during a previous session, save whatever part of the user data (from getUser()) you want in LocalStorage.

logout

logout()

Tells the server to invalidate the tokens and clears them from memory on the client.

getUser

const user = Accounts.getUser()

Fetches the currently logged-in user record.

sendVerificationEmail

sendVerificationEmail(emailAddress)

Sends an email which contains a link to this app with a secret token in the URL.

verifyEmail

verifyEmail(token)

  • token: retrieved from the URL (the link clicked in the verification email)

requestPasswordReset

requestPasswordReset(emailAddress)

Sends an email which contains a link to this app with a secret token in the URL.

resetPassword

resetPassword(token, newPassword)

  • token: retrieved from the URL (the link clicked in the reset password email)

changePassword

changePassword(old, new)

getTwoFactorSecret

const secret = Accounts.getTwoFactorSecret()

  • secret:
    • base32: backup code for user to write down if they'd like
    • otpauth_url: a QR code to be displayed, for instance with qrcode.react: <QRCode value={secret.otpauth_url} />

Example usage

twoFactorSet

twoFactorSet(secret, oneTimeCode)

  • secret obtained from getTwoFactorSecret
  • oneTimeCode entered by the user after they use an app like Authy to scan the QR code.

impersonate

impersonate(user)

  • user: { userId } or { username } or { email }

If the current user has the correct authorization (see options.impersonationAuthorize), this fetches and saves the target user's tokens.

stopImpersonation

stopImpersonation()

Deletes the impersonated user's tokens and restores the original user's tokens.

Eject

This package is like Apollo Boost—if at some point you need more configuration options than this package exposes, you can eject by directly installing the below accounts-js packages and configuring them yourself:

npm install @accounts/client @accounts/client-password @accounts/graphql-client

import ApolloClient from 'apollo-boost'

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

Credits