Last active
October 4, 2017 16:46
-
-
Save wking-io/a8f5aafd0824bd8ffa1afc7a02e687df to your computer and use it in GitHub Desktop.
Check User Auth Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { graphql, gql } from 'react-apollo'; | |
import storage from 'store'; | |
const isLoggedIn = ({ children, user }) => { | |
if(user) { | |
return children; | |
} | |
}; | |
const USER_QUERY = gql` | |
query allUser($id: ID!) { | |
user(id: $id) { | |
id | |
} | |
} | |
`; | |
// Use store package to grab users id from local storage and return the id if | |
// it is in graphcool. If not it will return null. | |
export default graphql(USER_QUERY, { | |
name: 'user', | |
options: { variables: { id: storage.get(GC_USER_ID) } }, | |
})(isLoggedIn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment