Skip to content

Commit

Permalink
Merge branch 'upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
ujwal-setlur committed Sep 30, 2018
2 parents 4c62ab0 + 4f5a5c4 commit 3b30e58
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 72 deletions.
90 changes: 47 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A implementation of Meteor Accounts only in GraphQL with Apollo.

This package uses the Meteor Accounts methods in GraphQL, it's compatible with the accounts you have saved in your database and you may use apollo-accounts and Meteor's DPP accounts at the same time.
This package exposes Meteor Accounts functionality in GraphQL.

## Installing

Expand All @@ -25,6 +25,10 @@ const { typeDefs, resolvers } = initAccounts({
loginWithLinkedIn: false,
loginWithPhone: false,
loginWithPassword: true,
overrideCreateUser: (createUser, _, args, context) {
// Optionally override createUser if you need custom logic
// Or simply restrict him from authenticating
}
});

// optional
Expand All @@ -48,12 +52,12 @@ npm install --save meteor-apollo-accounts

## Examples

* [janikvonrotz/meteor-apollo-accounts-example](https://github.com/janikvonrotz/meteor-apollo-accounts-example): Meteor client and server side.
* [orionsoft/server-boilerplate](https://github.com/orionsoft/server-boilerplate): Large Meteor server side only starter app.
- [janikvonrotz/meteor-apollo-accounts-example](https://github.com/janikvonrotz/meteor-apollo-accounts-example): Meteor client and server side.
- [orionsoft/server-boilerplate](https://github.com/orionsoft/server-boilerplate): Large Meteor server side only starter app.

## Tutorials

* [Using Meteor With Apollo and React](https://blog.orionsoft.io/using-meteor-accounts-with-apollo-and-react-df3c89b46b17#.znozw2zbd)
- [Using Meteor With Apollo and React](https://blog.orionsoft.io/using-meteor-accounts-with-apollo-and-react-df3c89b46b17#.znozw2zbd)

## Methods

Expand All @@ -69,13 +73,13 @@ import { loginWithPassword } from 'meteor-apollo-accounts';
loginWithPassword({ username, email, password }, apollo);
```

* `username`: Optional. The user's username.
- `username`: Optional. The user's username.

* `email`: Optional. The user's email.
- `email`: Optional. The user's email.

* `password`: The user's password. The library will hash the string before it sends it to the server.
- `password`: The user's password. The library will hash the string before it sends it to the server.

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### changePassword

Expand All @@ -87,11 +91,11 @@ import { changePassword } from 'meteor-apollo-accounts';
changePassword({ oldPassword, newPassword }, apollo);
```

* `oldPassword`: The user's current password. This is not sent in plain text over the wire.
- `oldPassword`: The user's current password. This is not sent in plain text over the wire.

* `newPassword`: A new password for the user. This is not sent in plain text over the wire.
- `newPassword`: A new password for the user. This is not sent in plain text over the wire.

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### logout

Expand All @@ -103,7 +107,7 @@ import { logout } from 'meteor-apollo-accounts';
logout(apollo);
```

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### createUser

Expand All @@ -115,15 +119,15 @@ import { createUser } from 'meteor-apollo-accounts';
createUser({ username, email, password, profile }, apollo);
```

* `username`: A unique name for this user.
- `username`: A unique name for this user.

* `email`: The user's email address.
- `email`: The user's email address.

* `password`: The user's password. This is not sent in plain text over the wire.
- `password`: The user's password. This is not sent in plain text over the wire.

* `profile`: The profile object based on the `UserProfileInput` input type.
- `profile`: The profile object based on the `UserProfileInput` input type.

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### verifyEmail

Expand All @@ -135,9 +139,9 @@ import { verifyEmail } from 'meteor-apollo-accounts';
verifyEmail({ token }, apollo);
```

* `token`: The token retrieved from the verification URL.
- `token`: The token retrieved from the verification URL.

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### forgotPassword

Expand All @@ -149,9 +153,9 @@ import { forgotPassword } from 'meteor-apollo-accounts';
forgotPassword({ email }, apollo);
```

* `email`: The email address to send a password reset link.
- `email`: The email address to send a password reset link.

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### resetPassword

Expand All @@ -163,11 +167,11 @@ import { resetPassword } from 'meteor-apollo-accounts';
resetPassword({ newPassword, token }, apollo);
```

* `newPassword`: A new password for the user. This is not sent in plain text over the wire.
- `newPassword`: A new password for the user. This is not sent in plain text over the wire.

* `token`: The token retrieved from the reset password URL.
- `token`: The token retrieved from the reset password URL.

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### loginWithFacebook

Expand All @@ -179,10 +183,10 @@ import { loginWithFacebook } from 'meteor-apollo-accounts';
loginWithFacebook({ accessToken }, apollo);
```

* `accessToken`: A Facebook accessToken. It's recommended to use
- `accessToken`: A Facebook accessToken. It's recommended to use
https://github.com/keppelen/react-facebook-login to fetch the accessToken.

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### loginWithGoogle

Expand All @@ -194,10 +198,10 @@ import { loginWithGoogle } from 'meteor-apollo-accounts';
loginWithGoogle({ accessToken }, apollo);
```

* `accessToken`: A Google accessToken. It's recommended to use
- `accessToken`: A Google accessToken. It's recommended to use
https://github.com/anthonyjgrove/react-google-login to fetch the accessToken.

* `apollo`: Apollo client instance.
- `apollo`: Apollo client instance.

#### Phone support

Expand Down Expand Up @@ -234,12 +238,12 @@ To login with the verification code, use the following mutation:

```graphql
mutation loginWithPhone {
loginWithPhone (phone: "+11234567890", verificationCode: "6593") {
id
token
tokenExpires
}
}
loginWithPhone (phone: "+11234567890", verificationCode: "6593") {
id
token
tokenExpires
}
}
```

Server response:
Expand All @@ -265,10 +269,10 @@ To request a new verification code, use the following mutation:

```graphql
mutation resendPhoneVerification {
resendPhoneVerification (phone: "+11234567890") {
success
}
}
resendPhoneVerification (phone: "+11234567890") {
success
}
}
```

Server response:
Expand Down Expand Up @@ -356,8 +360,8 @@ async login (event) {

## Contributors

* [@theodorDiaconu](https://github.com/theodorDiaconu)
* [@nicolaslopezj](https://github.com/nicolaslopezj)
* [@janikvonrotz](https://github.com/janikvonrotz)
* [@dbrrt](https://github.com/dbrrt)
* [@hammadj](https://github.com/hammadj)
- [@theodorDiaconu](https://github.com/theodorDiaconu)
- [@nicolaslopezj](https://github.com/nicolaslopezj)
- [@janikvonrotz](https://github.com/janikvonrotz)
- [@dbrrt](https://github.com/dbrrt)
- [@hammadj](https://github.com/hammadj)
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Package.describe({
name: 'cultofcoders:apollo-accounts',
version: '3.2.4',
version: '3.3.0',
// Brief, one-line summary of the package.
summary: 'Meteor accounts in GraphQL',
// URL to the Git repository containing the source code for this package.
Expand Down
8 changes: 4 additions & 4 deletions src/Auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function (options) {
export default function(options) {
return `
# Type returned when the user logs in
type LoginMethodResponse {
Expand All @@ -7,7 +7,7 @@ type LoginMethodResponse {
# Token of the connection
token: String!
# Expiration date for the token
tokenExpires: Float!
tokenExpires: String!
# The logged in user
user: User
}
Expand All @@ -16,7 +16,7 @@ input CreateUserProfileInput {
${options.CreateUserProfileInput}
}
type SuccessResponse {
type AuthSuccessResponse {
# True if it succeeded
success: Boolean
}
Expand All @@ -28,5 +28,5 @@ input HashedPassword {
# Algorithm used to hash the password
algorithm: String!
}
`
`;
}
28 changes: 19 additions & 9 deletions src/Mutation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,30 @@ import resetPassword from './resetPassword'
import oauth from './oauth'
import hasService from './oauth/hasService'

export default function (options) {
export default function(options) {
const resolvers = {
logout,
verifyEmail,
resendVerificationEmail,
...oauth(options)
}
...oauth(options),
};

if (hasService(options, 'password')) {
resolvers.loginWithPassword = loginWithPassword
resolvers.changePassword = changePassword
resolvers.createUser = createUser
resolvers.forgotPassword = forgotPassword
resolvers.resetPassword = resetPassword
resolvers.loginWithPassword = loginWithPassword;
resolvers.changePassword = changePassword;

// TODO: maybe allow hooks for other implementations as well
// Maybe do not allow login without email verification?
resolvers.createUser = async (...args) => {
if (options.overrideCreateUser) {
return options.overrideCreateUser(createUser, ...args);
}

return createUser.call(null, ...args);
};

resolvers.forgotPassword = forgotPassword;
resolvers.resetPassword = resetPassword;
}

if (hasService(options, 'phone')) {
Expand All @@ -34,5 +44,5 @@ export default function (options) {
resolvers.resendPhoneVerification = resendPhoneVerification
}

return {Mutation: resolvers}
return { Mutation: resolvers };
}
30 changes: 15 additions & 15 deletions src/Mutations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hasService from './Mutation/oauth/hasService'
import hasService from './Mutation/oauth/hasService';

export default function (options) {
const mutations = []
export default function(options) {
const mutations = [];

if (hasService(options, 'password')) {
mutations.push(`
Expand All @@ -13,14 +13,14 @@ export default function (options) {
createUser (username: String, email: String, password: HashedPassword, plainPassword: String, profile: CreateUserProfileInput): LoginMethodResponse
# Change the current user's password. Must be logged in.
changePassword (oldPassword: HashedPassword!, newPassword: HashedPassword!): SuccessResponse
changePassword (oldPassword: HashedPassword!, newPassword: HashedPassword!): AuthSuccessResponse
# Request a forgot password email.
forgotPassword (email: String!): SuccessResponse
forgotPassword (email: String!): AuthSuccessResponse
# Reset the password for a user using a token received in email. Logs the user in afterwards.
resetPassword (newPassword: HashedPassword!, token: String!): LoginMethodResponse
}`)
}`);
}

if (hasService(options, 'phone')) {
Expand All @@ -30,48 +30,48 @@ export default function (options) {
loginWithPhone (phone: String, verificationCode: String): LoginMethodResponse
# Create a new user with a phone.
createUserWithPhone (phone: String, password: String, profile: CreateUserProfileInput): SuccessResponse
createUserWithPhone (phone: String, password: String, profile: CreateUserProfileInput): AuthSuccessResponse
# Send verification code to phone.
resendPhoneVerification (phone: String): SuccessResponse
resendPhoneVerification (phone: String): AuthSuccessResponse
}`)
}

mutations.push(`
type Mutation {
# Log the user out.
logout (token: String!): SuccessResponse
logout (token: String!): AuthSuccessResponse
# Marks the user's email address as verified. Logs the user in afterwards.
verifyEmail (token: String!): LoginMethodResponse
# Send an email with a link the user can use verify their email address.
resendVerificationEmail (email: String): SuccessResponse
}`)
resendVerificationEmail (email: String): AuthSuccessResponse
}`);

if (hasService(options, 'facebook')) {
mutations.push(`
type Mutation {
# Login the user with a facebook access token
loginWithFacebook (accessToken: String!): LoginMethodResponse
}`)
}`);
}

if (hasService(options, 'google')) {
mutations.push(`
type Mutation {
# Login the user with a facebook access token
loginWithGoogle (accessToken: String!, tokenId: String): LoginMethodResponse
}`)
}`);
}

if (hasService(options, 'linkedin')) {
mutations.push(`
type Mutation {
# Login the user with a facebook access token
loginWithLinkedIn (code: String!, redirectUri: String!): LoginMethodResponse
}`)
}`);
}

return mutations
return mutations;
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const initAccounts = function(givenOptions) {
loginWithLinkedIn: false,
loginWithPassword: true,
loginWithPhone: false,
overrideCreateUser: null, // createUser, args, context
};
const options = {
...defaultOptions,
Expand Down

0 comments on commit 3b30e58

Please sign in to comment.