Skip to content

Instantly share code, notes, and snippets.

@abhitheawesomecoder
Last active November 5, 2017 06:46
Show Gist options
  • Save abhitheawesomecoder/d4a3be49210854728275a6bfaae1dde4 to your computer and use it in GitHub Desktop.
Save abhitheawesomecoder/d4a3be49210854728275a6bfaae1dde4 to your computer and use it in GitHub Desktop.
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