Last active
November 5, 2017 06:46
-
-
Save abhitheawesomecoder/d4a3be49210854728275a6bfaae1dde4 to your computer and use it in GitHub Desktop.
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 { AsyncStorage } from 'react-native'; | |
import { ApolloProvider, createNetworkInterface, ApolloClient } from 'react-apollo' | |
import Mainuser from './components/mainuser' | |
import Login from './components/Login' | |
import Register from './components/Register' | |
const networkInterface = createNetworkInterface({ uri: 'http://192.168.1.3:4000/graphql' | |
}) | |
getUserId = async () => { | |
try { | |
const value = await AsyncStorage.getItem('user-token'); | |
if (value !== null){ | |
return value | |
} | |
} catch (error) { | |
console.log(error) | |
} | |
return null | |
} | |
networkInterface.use([{ | |
applyMiddleware(req, next) { | |
if (!req.options.headers) { | |
req.options.headers = {} | |
} | |
const jwt = getUserId() | |
//if(jwt){ | |
Promise.resolve(jwt).then(function(token) { | |
if(token) req.options.headers.authorization = `Bearer ${token}` | |
next() | |
}) | |
//} | |
} | |
}]) | |
const client = new ApolloClient({ networkInterface }) | |
export default ( | |
<ApolloProvider client={client}> | |
<Createuser /> | |
</ApolloProvider> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment