diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | components/LoginAuth0.js | 12 | ||||
| -rw-r--r-- | components/Signup.js | 68 | ||||
| -rw-r--r-- | config.js | 2 | ||||
| -rw-r--r-- | graphcool/.graphcoolrc | 3 | ||||
| -rw-r--r-- | graphcool/graphcool.yml | 56 | ||||
| -rw-r--r-- | graphcool/package-lock.json | 790 | ||||
| -rw-r--r-- | graphcool/package.json | 18 | ||||
| -rw-r--r-- | graphcool/project.graphcool (renamed from project.graphcool) | 0 | ||||
| -rw-r--r-- | graphcool/src/auth0/auth0Authentication.graphql | 8 | ||||
| -rw-r--r-- | graphcool/src/auth0/auth0Authentication.js | 104 | ||||
| -rw-r--r-- | graphcool/src/createCharge.js (renamed from functions/createCharge.js) | 11 | ||||
| -rw-r--r-- | graphcool/src/createCharge.test.js (renamed from functions/createCharge.test.js) | 0 | ||||
| -rw-r--r-- | graphcool/src/getPrice.js (renamed from functions/getPrice.js) | 0 | ||||
| -rw-r--r-- | graphcool/src/hello.graphql | 7 | ||||
| -rw-r--r-- | graphcool/src/hello.js | 11 | ||||
| -rw-r--r-- | graphcool/src/index.js (renamed from functions/index.js) | 0 | ||||
| -rw-r--r-- | graphcool/types.graphql | 56 |
18 files changed, 1114 insertions, 35 deletions
@@ -2,4 +2,5 @@ node_modules/ .DS_Store *.log haters/ -.next/
\ No newline at end of file +.next/ +.build/
\ No newline at end of file diff --git a/components/LoginAuth0.js b/components/LoginAuth0.js index 8691e82..b55ae4a 100644 --- a/components/LoginAuth0.js +++ b/components/LoginAuth0.js @@ -7,8 +7,8 @@ class LoginAuth0 extends Component { constructor(props) { super(props); if (typeof window === 'undefined') return; - const redirectUrl = `http://localhost:6969/signup`; - this._lock = new Auth0Lock('l851ev2q8X48wf56eGLjIWFbMwwbvWPE', 'wesbos.auth0.com', { + const redirectUrl = `http://localhost:3000/signup`; + this._lock = new Auth0Lock('r6D64Waoq7roAnv8GT04dnn1tpq9PAqu', 'wesbos.auth0.com', { auth: { redirect: false, }, @@ -16,11 +16,17 @@ class LoginAuth0 extends Component { } componentDidMount() { - console.log('MOUNT'); this._lock.on('authenticated', authResult => { + console.log(authResult); window.localStorage.setItem('auth0IdToken', authResult.idToken); + console.log('Im baaaack!'); this.props.currentUserQuery.refetch(); }); + + this._lock.on('authorization_error', err => { + console.error(err); + }); + // refech on page load because of the server render this.props.currentUserQuery.refetch(); } diff --git a/components/Signup.js b/components/Signup.js index ab0a498..57e2569 100644 --- a/components/Signup.js +++ b/components/Signup.js @@ -1,52 +1,68 @@ -import React, { Component } from 'react' -import { graphql, gql } from 'react-apollo' +import React, { Component } from 'react'; +import { graphql, gql } from 'react-apollo'; import { CREATE_USER_MUTATION } from '../queries'; class Signup extends Component { - constructor() { super(); - const idToken = typeof window !== 'undefined' ? localStorage.getItem('auth0IdToken') || '' : ''; + const idToken = typeof window !== 'undefined' ? localStorage.getItem('auth0IdToken') || '' : ''; this.state = { email: '', name: '', idToken, - error: undefined - } - + error: undefined, + }; } - render() { return ( <div> - { this.state.loading ? 'LOADING...' : 'Ready!' } + {this.state.loading ? 'LOADING...' : 'Ready!'} - { this.state.error ? <p>{this.state.error.message}</p> : '' } + {this.state.error ? <p>{this.state.error.message}</p> : ''} <form onSubmit={this._createUser}> - <p>Email - <input value={this.state.email} onChange={(e) => this.setState({ email: e.target.value })} type='text' placeholder='email'/> + <p> + Email + <input + value={this.state.email} + onChange={e => this.setState({ email: e.target.value })} + type="text" + placeholder="email" + /> </p> - <p>Name - <input value={this.state.name} onChange={(e) => this.setState({ name: e.target.value })} type='text' placeholder='name'/> + <p> + Name + <input + value={this.state.name} + onChange={e => this.setState({ name: e.target.value })} + type="text" + placeholder="name" + /> </p> - <p>idToken - <input disabled value={this.state.idToken} onChange={(e) => this.setState({ idToken: e.target.value })} type='text' placeholder='name'/> + <p> + idToken + <input + disabled + value={this.state.idToken} + onChange={e => this.setState({ idToken: e.target.value })} + type="text" + placeholder="name" + /> </p> <button type="submit">Submit</button> </form> </div> - ) + ); } - _createUser = async (e) => { + _createUser = async e => { e.preventDefault(); // pull the values from state - const { email, name, idToken } = this.state + const { email, name, idToken } = this.state; // create a mutation // TODO: handle any errors // turn loading on @@ -55,22 +71,24 @@ class Signup extends Component { try { const res = await this.props.createUserMutation({ // pass in those variables from state - variables: { name, email, idToken } + variables: { name, email, idToken }, }); - } catch(error) { + } catch (error) { this.setState({ error }); console.dir(error); } this.setState({ loading: false }); - } + }; } // When we submit this mutation, we need to update our store - we have a few ways to do that: // One - we can go nucular and run refetchQueries() which will just go get everything - this is easy, but at the cost of efficiency. - -export default graphql(CREATE_USER_MUTATION, { name: 'createUserMutation', options: { +export default graphql(CREATE_USER_MUTATION, { + name: 'createUserMutation', + options: { // Easy, but slow // refetchQueries: ['AllLinksQuery'] // This is much Better / efficient // Notice how the variable is called createItem - that is because createItem is the name of the query! - } })(Signup) + }, +})(Signup); @@ -1,5 +1,5 @@ // This is client side config only - don't put anything in here that shouldn't be public! -export const projectId = `cj5xz8szs28930145gct82bdj`; +export const projectId = `cj99zm6ye06sb01325ic751ww`; export const endpoint = `https://api.graph.cool/simple/v1/${projectId}`; export const imageEndpoint = `https://images.graph.cool/v1/${projectId}`; export const fileEndpoint = `https://api.graph.cool/file/v1/${projectId}`; diff --git a/graphcool/.graphcoolrc b/graphcool/.graphcoolrc new file mode 100644 index 0000000..69adc85 --- /dev/null +++ b/graphcool/.graphcoolrc @@ -0,0 +1,3 @@ +targets: + Sick Fits 2: shared-eu-west-1/cj99zm6ye06sb01325ic751ww + default: Sick Fits 2 diff --git a/graphcool/graphcool.yml b/graphcool/graphcool.yml new file mode 100644 index 0000000..eb3f085 --- /dev/null +++ b/graphcool/graphcool.yml @@ -0,0 +1,56 @@ +# Welcome to Graphcool! +# +# This file is the main config file for your Graphcool Service. +# It's very minimal at this point and uses default values. +# We've included a hello world function here. +# Just run `graphcool deploy` to have the first running Graphcool Service. +# +# Check out some examples: +# https://github.com/graphcool/graphcool/tree/master/examples +# +# Here are the reference docs of this definition format: +# https://docs-next.graph.cool/reference/service-definition/graphcool.yml-foatho8aip +# +# Happy Coding! + + +# In the types.graphql you define your data schema +types: ./types.graphql + + +functions: + +# added by auth0 template: (please uncomment) +# + authenticate: + handler: + code: + src: ./src/auth0/auth0Authentication.js + environment: + AUTH0_DOMAIN: wesbos.auth0.com + AUTH0_API_IDENTIFIER: https://wesbos.auth0.com/api/v2/ + type: resolver + schema: ./src/auth0/auth0Authentication.graphql + + createCharge: + handler: + code: src/createCharge.js + type: operationBefore + operation: Order.create + + +# Model/Relation permissions are used to limit the API access +# To take the burden of thinking about those while development, we +# preconfigured the wildcard ("*") permission that allows everything +# Read more here: +# https://docs-next.graph.cool/reference/auth/authorization/overview-iegoo0heez +permissions: +- operation: "*" + + +# Your root tokens used for functions to get full access to the API +# Read more here: +# https://docs-next.graph.cool/reference/auth/authentication/authentication-tokens-eip7ahqu5o +# rootTokens: +# - mytoken + diff --git a/graphcool/package-lock.json b/graphcool/package-lock.json new file mode 100644 index 0000000..7907621 --- /dev/null +++ b/graphcool/package-lock.json @@ -0,0 +1,790 @@ +{ + "name": "graphcool", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/body-parser": { + "version": "1.16.7", + "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.16.7.tgz", + "integrity": "sha512-Obn1/GG0sYsnlAlhhSR1hvYRGBpQT+fzSi2IlGN8emCE4iu6f6xIjaq499B1sa7N9iBLzxyOUBo5bzgJd16BvA==", + "requires": { + "@types/express": "4.0.39", + "@types/node": "8.0.47" + } + }, + "@types/express": { + "version": "4.0.39", + "resolved": "https://registry.npmjs.org/@types/express/-/express-4.0.39.tgz", + "integrity": "sha512-dBUam7jEjyuEofigUXCtublUHknRZvcRgITlGsTbFgPvnTwtQUt2NgLakbsf+PsGo/Nupqr3IXCYsOpBpofyrA==", + "requires": { + "@types/body-parser": "1.16.7", + "@types/express-serve-static-core": "4.0.55", + "@types/serve-static": "1.13.0" + } + }, + "@types/express-jwt": { + "version": "0.0.34", + "resolved": "https://registry.npmjs.org/@types/express-jwt/-/express-jwt-0.0.34.tgz", + "integrity": "sha1-/b7kxq9cCiRu8qkz9VGZc8dxfwI=", + "requires": { + "@types/express": "4.0.39", + "@types/express-unless": "0.0.32" + } + }, + "@types/express-serve-static-core": { + "version": "4.0.55", + "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.0.55.tgz", + "integrity": "sha512-sDFubLXpgiluVW+2txOp877cQp7FyWYB9eMJTm3oAsX4HlGqIKiPcNpJq5XDKCTOMuVbnNMALYmayaj9KlRntg==", + "requires": { + "@types/node": "8.0.47" + } + }, + "@types/express-unless": { + "version": "0.0.32", + "resolved": "https://registry.npmjs.org/@types/express-unless/-/express-unless-0.0.32.tgz", + "integrity": "sha512-6YpJyFNlDDnPnRjMOvJCoDYlSDDmG/OEEUsPk7yhNkL4G9hUYtgab6vi1CcWsGSSSM0CsvNlWTG+ywAGnvF03g==", + "requires": { + "@types/express": "4.0.39" + } + }, + "@types/mime": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/mime/-/mime-2.0.0.tgz", + "integrity": "sha512-A2TAGbTFdBw9azHbpVd+/FkdW2T6msN1uct1O9bH3vTerEHKZhTXJUQXy+hNq1B0RagfU8U+KBdqiZpxjhOUQA==" + }, + "@types/node": { + "version": "8.0.47", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.47.tgz", + "integrity": "sha512-kOwL746WVvt/9Phf6/JgX/bsGQvbrK5iUgzyfwZNcKVFcjAUVSpF9HxevLTld2SG9aywYHOILj38arDdY1r/iQ==" + }, + "@types/serve-static": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.0.tgz", + "integrity": "sha512-wvQkePwCDZoyQPGb64DTl2TEeLw54CQFXjY+tznxYYxNcBb4LG40ezoVbMDa0epwE4yogB0f42jCaH0356x5Mg==", + "requires": { + "@types/express-serve-static-core": "4.0.55", + "@types/mime": "2.0.0" + } + }, + "ajv": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.3.0.tgz", + "integrity": "sha1-RBT/dKUIecII7l/cgm4ywwNUnto=", + "requires": { + "co": "4.6.0", + "fast-deep-equal": "1.0.0", + "fast-json-stable-stringify": "2.0.0", + "json-schema-traverse": "0.3.1" + } + }, + "apollo-fetch": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/apollo-fetch/-/apollo-fetch-0.6.0.tgz", + "integrity": "sha1-qumyjBF680SwkeyLpNGlqgR03F0=", + "requires": { + "isomorphic-fetch": "2.2.1" + } + }, + "apollo-link": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/apollo-link/-/apollo-link-0.7.0.tgz", + "integrity": "sha512-LPwygaqW57k7D5rKEdd5xZcLL7SY7MbUkvDYXfU/+el6Iq46AXfxJICXrU6UVydngEBD1DYm0t8CT4JRk0MR7g==", + "requires": { + "apollo-utilities": "0.2.0-rc.3", + "graphql": "0.11.7", + "zen-observable-ts": "0.5.0" + } + }, + "apollo-link-http": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/apollo-link-http/-/apollo-link-http-0.7.0.tgz", + "integrity": "sha512-BCYxduD5oHfsiWz15pcjooyAsP4E6gmL1BH4z4ikwU6I++QhbIBt5zH+ezUQcOKcozNY7+ZfcA4oaRud9FbkbA==", + "requires": { + "apollo-fetch": "0.6.0", + "graphql": "0.11.7" + } + }, + "apollo-utilities": { + "version": "0.2.0-rc.3", + "resolved": "https://registry.npmjs.org/apollo-utilities/-/apollo-utilities-0.2.0-rc.3.tgz", + "integrity": "sha512-UM5ok/DUKSgh/3T302hoPqCAhqfXdvBaQKOQJb0QUuX3qu2qVKzvwFsv/C3zWYySeCJTP9EoV2LtooIJOhSL4g==" + }, + "asn1": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", + "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" + }, + "assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" + }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" + }, + "aws4": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.6.0.tgz", + "integrity": "sha1-g+9cqGCysy5KDe7e6MdxudtXRx4=" + }, + "base64url": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz", + "integrity": "sha1-6sFuA+oUOO/5Qj1puqNiYu0fcLs=" + }, + "bcrypt-pbkdf": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz", + "integrity": "sha1-Y7xdy2EzG5K8Bf1SiVPDNGKgb40=", + "optional": true, + "requires": { + "tweetnacl": "0.14.5" + } + }, + "bluebird": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", + "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" + }, + "boom": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/boom/-/boom-4.3.1.tgz", + "integrity": "sha1-T4owBctKfjiJ90kDD9JbluAdLjE=", + "requires": { + "hoek": "4.2.0" + } + }, + "buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" + }, + "caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" + }, + "co": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" + }, + "combined-stream": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.5.tgz", + "integrity": "sha1-k4NwpXtKUd6ix3wV1cX9+JUWQAk=", + "requires": { + "delayed-stream": "1.0.0" + } + }, + "core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" + }, + "cross-fetch": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-0.0.8.tgz", + "integrity": "sha1-Ae2U3EB98sAPGAf95wCnz6SKIFw=", + "requires": { + "node-fetch": "1.7.3", + "whatwg-fetch": "2.0.3" + } + }, + "cryptiles": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/cryptiles/-/cryptiles-3.1.2.tgz", + "integrity": "sha1-qJ+7Ig9c4l7FboxKqKT9e1sNKf4=", + "requires": { + "boom": "5.2.0" + }, + "dependencies": { + "boom": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/boom/-/boom-5.2.0.tgz", + "integrity": "sha512-Z5BTk6ZRe4tXXQlkqftmsAUANpXmuwlsF5Oov8ThoMbQRzdGTA1ngYRW160GexgOgjsFOKJz0LYhoNi+2AMBUw==", + "requires": { + "hoek": "4.2.0" + } + } + } + }, + "dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "requires": { + "assert-plus": "1.0.0" + } + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" + }, + "deprecated-decorator": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/deprecated-decorator/-/deprecated-decorator-0.1.6.tgz", + "integrity": "sha1-AJZjF7ehL+kvPMgx91g68ym4bDc=" + }, + "ecc-jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz", + "integrity": "sha1-D8c6ntXw1Tw4GTOYUj735UN3dQU=", + "optional": true, + "requires": { + "jsbn": "0.1.1" + } + }, + "ecdsa-sig-formatter": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.9.tgz", + "integrity": "sha1-S8kmJ07Dtau1AW5+HWCSGsJisqE=", + "requires": { + "base64url": "2.0.0", + "safe-buffer": "5.1.1" + } + }, + "encoding": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", + "requires": { + "iconv-lite": "0.4.19" + } + }, + "extend": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", + "integrity": "sha1-p1Xqe8Gt/MWjHOfnYtuq3F5jZEQ=" + }, + "extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" + }, + "fast-deep-equal": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz", + "integrity": "sha1-liVqO8l1WV6zbYLpkp0GDYk0Of8=" + }, + "fast-json-stable-stringify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" + }, + "forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" + }, + "form-data": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.1.tgz", + "integrity": "sha1-b7lPvXGIUwbXPRXMSX/kzE7NRL8=", + "requires": { + "asynckit": "0.4.0", + "combined-stream": "1.0.5", + "mime-types": "2.1.17" + } + }, + "getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "requires": { + "assert-plus": "1.0.0" + } + }, + "graphcool-lib": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/graphcool-lib/-/graphcool-lib-0.1.4.tgz", + "integrity": "sha512-qUmcS+nQLPR3gTOvfQbHAdwKkwBJlUIm1SNb+5lcPkh3iIPXSISHJcpt7kECNB2s75O8shKYGMXJRd3F5S2Aaw==", + "requires": { + "apollo-link": "0.7.0", + "apollo-link-http": "0.7.0", + "graphql": "0.11.7", + "graphql-request": "1.4.0", + "graphql-tools": "2.6.1", + "node-fetch": "1.7.3", + "source-map-support": "0.4.18" + } + }, + "graphql": { + "version": "0.11.7", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-0.11.7.tgz", + "integrity": "sha512-x7uDjyz8Jx+QPbpCFCMQ8lltnQa4p4vSYHx6ADe8rVYRTdsyhCJbvSty5DAsLVmU6cGakl+r8HQYolKHxk/tiw==", + "requires": { + "iterall": "1.1.3" + } + }, + "graphql-request": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/graphql-request/-/graphql-request-1.4.0.tgz", + "integrity": "sha512-lAAbaq2IbeN4sGcgQgx/OtxEZ9UimpWawIEUYAw8Dk0yNAYPwWH79/ASdGrH/5aTvYHz3U7CjgoQmaiUpLJ3qw==", + "requires": { + "cross-fetch": "0.0.8" + } + }, + "graphql-tools": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/graphql-tools/-/graphql-tools-2.6.1.tgz", + "integrity": "sha1-n20WAJUaBbGLg8UphsQu7k/Tyxs=", + "requires": { + "apollo-utilities": "0.1.1-1", + "deprecated-decorator": "0.1.6", + "uuid": "3.1.0" + }, + "dependencies": { + "apollo-utilities": { + "version": "0.1.1-1", + "resolved": "https://registry.npmjs.org/apollo-utilities/-/apollo-utilities-0.1.1-1.tgz", + "integrity": "sha512-1254/E4u7B5niFoR7h3RF+Bxv+KjAe6StEHUXABeDOIcVHkjjLHx++ZKDdZeTjwDow4tMc5fkhwpZ5vzxezyxQ==" + } + } + }, + "har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" + }, + "har-validator": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.0.3.tgz", + "integrity": "sha1-ukAsJmGU8VlW7xXg/PJCmT9qff0=", + "requires": { + "ajv": "5.3.0", + "har-schema": "2.0.0" + } + }, + "hawk": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/hawk/-/hawk-6.0.2.tgz", + "integrity": "sha512-miowhl2+U7Qle4vdLqDdPt9m09K6yZhkLDTWGoUiUzrQCn+mHHSmfJgAyGaLRZbPmTqfFFjRV1QWCW0VWUJBbQ==", + "requires": { + "boom": "4.3.1", + "cryptiles": "3.1.2", + "hoek": "4.2.0", + "sntp": "2.1.0" + } + }, + "hoek": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/hoek/-/hoek-4.2.0.tgz", + "integrity": "sha512-v0XCLxICi9nPfYrS9RL8HbYnXi9obYAeLbSP00BmnZwCK9+Ih9WOjoZ8YoHCoav2csqn4FOz4Orldsy2dmDwmQ==" + }, + "http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", + "requires": { + "assert-plus": "1.0.0", + "jsprim": "1.4.1", + "sshpk": "1.13.1" + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" + }, + "isomorphic-fetch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", + "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", + "requires": { + "node-fetch": "1.7.3", + "whatwg-fetch": "2.0.3" + } + }, + "isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" + }, + "iterall": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/iterall/-/iterall-1.1.3.tgz", + "integrity": "sha512-Cu/kb+4HiNSejAPhSaN1VukdNTTi/r4/e+yykqjlG/IW+1gZH5b4+Bq3whDX4tvbYugta3r8KTMUiqT3fIGxuQ==" + }, + "jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "optional": true + }, + "json-schema": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" + }, + "json-schema-traverse": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=" + }, + "json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" + }, + "jsonwebtoken": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.1.0.tgz", + "integrity": "sha1-xjl80uX9WD1lwAeoPce7eOaYK4M=", + "requires": { + "jws": "3.1.4", + "lodash.includes": "4.3.0", + "lodash.isboolean": "3.0.3", + "lodash.isinteger": "4.0.4", + "lodash.isnumber": "3.0.3", + "lodash.isplainobject": "4.0.6", + "lodash.isstring": "4.0.1", + "lodash.once": "4.1.1", + "ms": "2.0.0", + "xtend": "4.0.1" + } + }, + "jsprim": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", + "requires": { + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.2.3", + "verror": "1.10.0" + } + }, + "jwa": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-1.1.5.tgz", + "integrity": "sha1-oFUs4CIHQs1S4VN3SjKQXDDnVuU=", + "requires": { + "base64url": "2.0.0", + "buffer-equal-constant-time": "1.0.1", + "ecdsa-sig-formatter": "1.0.9", + "safe-buffer": "5.1.1" + } + }, + "jwks-rsa": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/jwks-rsa/-/jwks-rsa-1.2.1.tgz", + "integrity": "sha512-xg+fw7FOV4eGdDIEMqQJvPLmFv85h4uN+j/GKwJZAxlCrDQpM8ov1F709xKGEp/dG3l4TUxoSOeN6YK7+KpinQ==", + "requires": { + "@types/express-jwt": "0.0.34", + "debug": "2.6.9", + "limiter": "1.1.2", + "lru-memoizer": "1.11.1", + "ms": "2.0.0", + "request": "2.83.0" + } + }, + "jws": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/jws/-/jws-3.1.4.tgz", + "integrity": "sha1-+ei5M46KhHJ31kRLFGT2GIDgUKI=", + "requires": { + "base64url": "2.0.0", + "jwa": "1.1.5", + "safe-buffer": "5.1.1" + } + }, + "limiter": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/limiter/-/limiter-1.1.2.tgz", + "integrity": "sha512-JIKZ0xb6fZZYa3deZ0BgXCgX6HgV8Nx3mFGeFHmFWW8Fb2c08e0CyE+G3nalpD0xGvGssjGb1UdFr+PprxZEbw==" + }, + "lock": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/lock/-/lock-0.1.4.tgz", + "integrity": "sha1-/sfervF+fDoKVeHaBCgD4l2RdF0=" + }, + "lodash": { + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.5.1.tgz", + "integrity": "sha1-gOigdMpfOJOmscELKmNkktcQwxY=" + }, + "lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha1-YLuYqHy5I8aMoeUTJUgzFISfVT8=" + }, + "lodash.isboolean": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", + "integrity": "sha1-bC4XHbKiV82WgC/UOwGyDV9YcPY=" + }, + "lodash.isinteger": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", + "integrity": "sha1-YZwK89A/iwTDH1iChAt3sRzWg0M=" + }, + "lodash.isnumber": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", + "integrity": "sha1-POdoEMWSjQM1IwGsKHMX8RwLH/w=" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "lodash.isstring": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", + "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=" + }, + "lodash.once": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", + "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" + }, + "lru-cache": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.0.2.tgz", + "integrity": "sha1-HRdnnAac2l0ECZGgnbwsDbN35V4=", + "requires": { + "pseudomap": "1.0.2", + "yallist": "2.1.2" + } + }, + "lru-memoizer": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/lru-memoizer/-/lru-memoizer-1.11.1.tgz", + "integrity": "sha1-BpP2EAWTkUwC4ZK/m42TiEy/UNM=", + "requires": { + "lock": "0.1.4", + "lodash": "4.5.1", + "lru-cache": "4.0.2", + "very-fast-args": "1.1.0" + } + }, + "mime-db": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz", + "integrity": "sha1-dMZD2i3Z1qRTmZY0ZbJtXKfXHwE=" + }, + "mime-types": { + "version": "2.1.17", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", + "integrity": "sha1-Cdejk/A+mVp5+K+Fe3Cp4KsWVXo=", + "requires": { + "mime-db": "1.30.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "requires": { + "encoding": "0.1.12", + "is-stream": "1.1.0" + } + }, + "oauth-sign": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", + "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" + }, + "performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" + }, + "pseudomap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" + }, + "punycode": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" + }, + "qs": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + }, + "request": { + "version": "2.83.0", + "resolved": "https://registry.npmjs.org/request/-/request-2.83.0.tgz", + "integrity": "sha512-lR3gD69osqm6EYLk9wB/G1W/laGWjzH90t1vEa2xuxHD5KUrSzp9pUSfTm+YC5Nxt2T8nMPEvKlhbQayU7bgFw==", + "requires": { + "aws-sign2": "0.7.0", + "aws4": "1.6.0", + "caseless": "0.12.0", + "combined-stream": "1.0.5", + "extend": "3.0.1", + "forever-agent": "0.6.1", + "form-data": "2.3.1", + "har-validator": "5.0.3", + "hawk": "6.0.2", + "http-signature": "1.2.0", + "is-typedarray": "1.0.0", + "isstream": "0.1.2", + "json-stringify-safe": "5.0.1", + "mime-types": "2.1.17", + "oauth-sign": "0.8.2", + "performance-now": "2.1.0", + "qs": "6.5.1", + "safe-buffer": "5.1.1", + "stringstream": "0.0.5", + "tough-cookie": "2.3.3", + "tunnel-agent": "0.6.0", + "uuid": "3.1.0" + } + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + }, + "sntp": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/sntp/-/sntp-2.1.0.tgz", + "integrity": "sha512-FL1b58BDrqS3A11lJ0zEdnJ3UOKqVxawAkF3k7F0CVN7VQ34aZrV+G8BZ1WC9ZL7NyrwsW0oviwsWDgRuVYtJg==", + "requires": { + "hoek": "4.2.0" + } + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=" + }, + "source-map-support": { + "version": "0.4.18", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.18.tgz", + "integrity": "sha512-try0/JqxPLF9nOjvSta7tVondkP5dwgyLDjVoyMDlmjugT2lRZ1OfsrYTkCd2hkDnJTKRbO/Rl3orm8vlsUzbA==", + "requires": { + "source-map": "0.5.7" + } + }, + "sshpk": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.13.1.tgz", + "integrity": "sha1-US322mKHFEMW3EwY/hzx2UBzm+M=", + "requires": { + "asn1": "0.2.3", + "assert-plus": "1.0.0", + "bcrypt-pbkdf": "1.0.1", + "dashdash": "1.14.1", + "ecc-jsbn": "0.1.1", + "getpass": "0.1.7", + "jsbn": "0.1.1", + "tweetnacl": "0.14.5" + } + }, + "stringstream": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", + "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=" + }, + "stripe": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/stripe/-/stripe-5.2.0.tgz", + "integrity": "sha512-Mjw4CEMa3bONxIkaaxnNd3HcMMWgw2ZaOj3NW1vqnJ9PCOmVuXWWHLiZ3HD4vz3Vqh8VjqL2bIW9C9KB39sA6w==", + "requires": { + "bluebird": "3.5.1", + "lodash.isplainobject": "4.0.6", + "qs": "6.5.1", + "safe-buffer": "5.1.1" + } + }, + "tough-cookie": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.3.3.tgz", + "integrity": "sha1-C2GKVWW23qkL80JdBNVe3EdadWE=", + "requires": { + "punycode": "1.4.1" + } + }, + "tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "requires": { + "safe-buffer": "5.1.1" + } + }, + "tweetnacl": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "optional": true + }, + "uuid": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", + "integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==" + }, + "verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "requires": { + "assert-plus": "1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "1.3.0" + } + }, + "very-fast-args": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/very-fast-args/-/very-fast-args-1.1.0.tgz", + "integrity": "sha1-4W0dH6+KbllqJGQh/ZCneWPQs5Y=" + }, + "whatwg-fetch": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", + "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=" + }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + }, + "yallist": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" + }, + "zen-observable-ts": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/zen-observable-ts/-/zen-observable-ts-0.5.0.tgz", + "integrity": "sha512-8soRu9VE2HYkAAKcDegToWzu8snITcZjujnE4SXc+7IczbHXRCFkd4Cj4DgYq88nU6SwTU5lkea7KBGNa/CaFw==" + } + } +} diff --git a/graphcool/package.json b/graphcool/package.json new file mode 100644 index 0000000..bc443d2 --- /dev/null +++ b/graphcool/package.json @@ -0,0 +1,18 @@ +{ + "name": "graphcool", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "isomorphic-fetch": "^2.2.1", + "stripe": "^5.2.0", + "graphcool-lib": "^0.1.0", + "jsonwebtoken": "^8.1.0", + "jwks-rsa": "^1.2.1" + } +} diff --git a/project.graphcool b/graphcool/project.graphcool index 193c9eb..193c9eb 100644 --- a/project.graphcool +++ b/graphcool/project.graphcool diff --git a/graphcool/src/auth0/auth0Authentication.graphql b/graphcool/src/auth0/auth0Authentication.graphql new file mode 100644 index 0000000..823a71b --- /dev/null +++ b/graphcool/src/auth0/auth0Authentication.graphql @@ -0,0 +1,8 @@ +type AuthenticateUserPayload { + id: String! + token: String! +} + +extend type Mutation { + authenticateUser(accessToken: String!): AuthenticateUserPayload +} diff --git a/graphcool/src/auth0/auth0Authentication.js b/graphcool/src/auth0/auth0Authentication.js new file mode 100644 index 0000000..4e1b4fa --- /dev/null +++ b/graphcool/src/auth0/auth0Authentication.js @@ -0,0 +1,104 @@ +const isomorphicFetch = require('isomorphic-fetch'); +const jwt = require('jsonwebtoken'); +const jwkRsa = require('jwks-rsa'); +const fromEvent = require('graphcool-lib').fromEvent; + +//Validates the request JWT token +const verifyToken = token => + new Promise(resolve => { + //Decode the JWT Token + const decoded = jwt.decode(token, { complete: true }); + if (!decoded || !decoded.header || !decoded.header.kid) { + throw new Error('Unable to retrieve key identifier from token'); + } + if (decoded.header.alg !== 'RS256') { + throw new Error( + `Wrong signature algorithm, expected RS256, got ${decoded.header.alg}` + ); + } + const jkwsClient = jwkRsa({ + cache: true, + jwksUri: `https://${process.env.AUTH0_DOMAIN}/.well-known/jwks.json` + }); + //Retrieve the JKWS's signing key using the decode token's key identifier (kid) + jkwsClient.getSigningKey(decoded.header.kid, (err, key) => { + if (err) throw new Error(err); + const signingKey = key.publicKey || key.rsaPublicKey; + //If the JWT Token was valid, verify its validity against the JKWS's signing key + jwt.verify( + token, + signingKey, + { + algorithms: ['RS256'], + audience: process.env.AUTH0_API_IDENTIFIER, + ignoreExpiration: false, + issuer: `https://${process.env.AUTH0_DOMAIN}/` + }, + (err, decoded) => { + if (err) throw new Error(err); + return resolve(decoded); + } + ); + }); + }); + +//Retrieves the Graphcool user record using the Auth0 user id +const getGraphcoolUser = (auth0UserId, api) => + api + .request( + ` + query getUser($auth0UserId: String!){ + User(auth0UserId: $auth0UserId){ + id + } + } + `, + { auth0UserId } + ) + .then(queryResult => queryResult.User); + +//Creates a new User record. +const createGraphCoolUser = ({ sub }, api) => + api + .request( + ` + mutation createUser($auth0UserId: String!) { + createUser( + auth0UserId: $auth0UserId + ){ + id + } + } + `, + { auth0UserId: sub } + ) + .then(queryResult => queryResult.createUser); + +export default async event => { + try { + if (!process.env.AUTH0_DOMAIN || !process.env.AUTH0_API_IDENTIFIER) { + throw new Error( + 'Missing AUTH0_DOMAIN or AUTH0_API_IDENTIFIER environment variable' + ); + } + const { accessToken } = event.data; + + const decodedToken = await verifyToken(accessToken); + const graphcool = fromEvent(event); + const api = graphcool.api('simple/v1'); + + let graphCoolUser = null; + + graphCoolUser = await getGraphcoolUser(decodedToken.sub, api); + //If the user doesn't exist. a new record is created. + if (graphCoolUser === null) { + graphCoolUser = await createGraphCoolUser(decodedToken, api); + } + const token = await graphcool.generateAuthToken(graphCoolUser.id, 'User'); + + return { data: { id: graphCoolUser.id, token } }; + } catch (err) { + console.log(err); + return { error: 'An unexpected error occured' }; + } +}; diff --git a/functions/createCharge.js b/graphcool/src/createCharge.js index 8dee76b..ccf9c11 100644 --- a/functions/createCharge.js +++ b/graphcool/src/createCharge.js @@ -1,6 +1,6 @@ -const stripe = require('stripe')('sk_ycLkGc2cAaBDSCKkHiKVBeT71CMxd') -; -const endpoint = 'https://api.graph.cool/simple/v1/cj5xz8szs28930145gct82bdj'; +const stripe = require('stripe')('sk_ycLkGc2cAaBDSCKkHiKVBeT71CMxd'); + +const endpoint = 'https://api.graph.cool/simple/v1/cj99zm6ye06sb01325ic751ww'; require('isomorphic-fetch'); @@ -22,11 +22,12 @@ const getPrice = itemId => { }); }; -const createStripeCharge = (token, amount) => stripe.charges.create({ +const createStripeCharge = (token, amount) => + stripe.charges.create({ amount, currency: 'usd', description: `a test charge`, - source: token + source: token, }); module.exports = function(event) { diff --git a/functions/createCharge.test.js b/graphcool/src/createCharge.test.js index 65dde47..65dde47 100644 --- a/functions/createCharge.test.js +++ b/graphcool/src/createCharge.test.js diff --git a/functions/getPrice.js b/graphcool/src/getPrice.js index 7808a85..7808a85 100644 --- a/functions/getPrice.js +++ b/graphcool/src/getPrice.js diff --git a/graphcool/src/hello.graphql b/graphcool/src/hello.graphql new file mode 100644 index 0000000..d43c729 --- /dev/null +++ b/graphcool/src/hello.graphql @@ -0,0 +1,7 @@ +type HelloPayload { + message: String! +} + +extend type Query { + hello(name: String): HelloPayload +} diff --git a/graphcool/src/hello.js b/graphcool/src/hello.js new file mode 100644 index 0000000..0e3e7ba --- /dev/null +++ b/graphcool/src/hello.js @@ -0,0 +1,11 @@ +export default async event => { + // you can use ES7 with async/await and even TypeScript in your functions :) + + await new Promise(r => setTimeout(r, 50)) + + return { + data: { + message: `Hello ${event.data.name || 'World'}` + } + } +}
\ No newline at end of file diff --git a/functions/index.js b/graphcool/src/index.js index ee451f6..ee451f6 100644 --- a/functions/index.js +++ b/graphcool/src/index.js diff --git a/graphcool/types.graphql b/graphcool/types.graphql new file mode 100644 index 0000000..dcdd690 --- /dev/null +++ b/graphcool/types.graphql @@ -0,0 +1,56 @@ +# The following types define the data model of the example service +# based on which the GraphQL API is generated + +type File @model { + contentType: String! + createdAt: DateTime! + id: ID! @isUnique + item: Item @relation(name: "Photo") + name: String! + secret: String! @isUnique + size: Int! + updatedAt: DateTime! + url: String! @isUnique +} + +type Item @model { + createdAt: DateTime! + description: String! + fullPrice: Int + id: ID! @isUnique + image: File @relation(name: "Photo") + order: Order @relation(name: "OrderOnItem") + price: Int + title: String! + updatedAt: DateTime! + user: User @relation(name: "CartItems") +} + +type Order @model { + amount: Int + charge: String + createdAt: DateTime! + id: ID! @isUnique + item: Item @relation(name: "OrderOnItem") + token: String + updatedAt: DateTime! + user: User @relation(name: "OrderOnUser") +} + +type User @model { + createdAt: DateTime! + email: String @isUnique + id: ID! @isUnique + isVerified: Boolean! @defaultValue(value: false) + orders: [Order!]! @relation(name: "OrderOnUser") + password: String + secret: String @isUnique + updatedAt: DateTime! + auth0UserId: String @isUnique + name: String! + cart: [Item!]! @relation(name: "CartItems") + level: Int +} + + + |
