Full-stack JS accounts system for Apollo and MongoDB
MIT License
Deprecated: This repo is out of date with the underlying accounts-js
library. We recommend using accounts-js
directly. Some of the below documentation may still be helpful.
Full-stack JS accounts system for Apollo and MongoDB
Compatible with Meteor's accounts-password
.
Based on accounts-js.
apollo-accounts-password-client
apollo-accounts-password-server
git clone https://github.com/flyblackbird/apollo-accounts
cd apollo-accounts
cd demo/web
npm install
npm start
cd demo/react-native
npm start
Either scan the QR code with the Expo app or open a simulator (eg hit i
for iOS simulator).
If you're using an existing accounts-password
Meteor app's database, you can first run meteor start
in your Meteor app directory and then add a MONGO_URL
to the npm start
command in the next section:
MONGO_URL="mongodb://localhost:3001/meteor" npm start
To start with a new database:
brew install docker-compose
If you run into an error, you might need to do:
sudo mkdir /usr/local/Frameworks
sudo chown $(whoami):admin /usr/local/Frameworks
Create a docker machine:
docker-machine create --driver virtualbox default
eval "$(docker-machine env default)"
Start mongo:
cd demo/server
docker-compose up -d
npm install
npm start
Determine the SHA256 of your password. For example if it's passwd
, then:
brew install openssl
echo -n passwd | openssl dgst -sha256
0d6be69b264717f2dd33652e212b173104b4a647b7c11ae72e9885f11cd312fb
Open GraphQL Playground at localhost:4000 and try these operations:
mutation {
register(user: { username: "loren", password: "0d6be69b264717f2dd33652e212b173104b4a647b7c11ae72e9885f11cd312fb" })
}
mutation {
authenticate(
serviceName: "password"
params: { user: { username: "loren" }, password: "0d6be69b264717f2dd33652e212b173104b4a647b7c11ae72e9885f11cd312fb" }
) {
tokens {
accessToken
}
}
}
query {
privateField
}
This package is configured to use the same hashing algorithms as Meteor's accounts-password
, and both it and Meteor stores user documents in a users
MongoDB collection, and the documents are in the same format, including a the services.password.bcrypt
field. So you can use the same database to back both a Meteor app and a node app using this package—a user created with one app will be able to login with the same username/email and password in the other app. If you are migrating away from Meteor, then after you've switched over to the node app, you can delete all of the services.resume
fields, as this package does not use them. (Instead, it creates a collection called sessions
.)
Some of the API methods are named differently (for instance login()
instead of loginWithPassword()
) or act differently (for instance taking different arguments, or in the case of onCreateUser()
, is executed after the user is stored instead of beforehand). Here are the client and server APIs.
There is no Meteor.user()
(or Tracker at all)—we recommend making a getUser()
query and subsequently reading the user object from the apollo cache for components that need it (for instance using a withUser
HOC). The alternative is making the query at the top of the component tree and passing the user
down as a prop, but for most apps that results in a ton of prop drilling.
Build and link packages:
git clone https://github.com/flyblackbird/apollo-accounts.git
cd apollo-accounts/client
npm run build
npm link
cd ../server
npm run build
npm link
Run server and web client:
cd ../demo/server
npm link apollo-accounts-password-server
npm install
npm start
cd demo/web
npm link apollo-accounts-password-client
npm install
npm start
RN doesn't like symlinks in node_modules/
, so we use wml
:
npm i -g wml
cd apollo-accounts
wml add client demo/react-native/node_modules/apollo-accounts-password-client
wml start
In another terminal:
rm -rf demo/react-native/node_modules/apollo-accounts-password-client/node_modules/
cd demo/react-native
npm start
Thank you to: