iamclaytonray
12/12/2017, 8:00 PMDukuo
12/12/2017, 8:08 PMiamclaytonray
12/12/2017, 8:09 PMloginUser(e) {
this.props.mutate({
variables: {
email: e.target.email.value,
password: e.target.password.value,
}
})
.then(() => {
const { email, password } = this.state;
const response = this.props.mutate({variables: { email, password }});
localStorage.setItem('token', response.data.authenticateUser.token);
}).catch((error) => {
console.log('An error occurred: ', error);
});
}
iamclaytonray
12/12/2017, 8:10 PMconst httpLink: ApolloLink = createHttpLink({
uri: LOCAL_SIMPLE_API
});
let cache: ApolloCache<any> = (new InMemoryCache() as ApolloCache<any>);
const authLink = setContext((_, { headers }) => {
const token = localStorage.getItem('token');
return {
headers: {
...headers,
authorization: token ? `Bearer ${token}` : null,
}
};
});
const clientOptions = {
link: authLink.concat(httpLink),
cache: cache,
};
iamclaytonray
12/12/2017, 8:13 PMkaihuang724
12/12/2017, 8:29 PMkaihuang724
12/12/2017, 8:29 PMkaihuang724
12/12/2017, 8:29 PMconst authMiddleware = setContext(operation =>
AsyncStorage.getItem("token").then(token => {
return {
headers: {
Authorization: `Bearer ${token}` || null
}
};
})
);
iamclaytonray
12/12/2017, 8:30 PMehodges
12/12/2017, 8:42 PMiamclaytonray
12/12/2017, 8:42 PMiamclaytonray
12/12/2017, 8:43 PM./constants.ts
ehodges
12/12/2017, 8:43 PMiamclaytonray
12/12/2017, 8:46 PMoperation
kaihuang724
12/12/2017, 8:47 PMiamclaytonray
12/12/2017, 8:49 PMBearer
in the localStorage value, forgetting that it was already set in my index.tsx
iamclaytonray
12/12/2017, 8:49 PMiamclaytonray
12/12/2017, 8:50 PMehodges
12/12/2017, 8:56 PMiamclaytonray
12/12/2017, 9:02 PMiamclaytonray
12/12/2017, 9:11 PMehodges
12/12/2017, 9:17 PMiamclaytonray
12/12/2017, 9:18 PMgraphcool-auth-token
to token
)ehodges
12/12/2017, 9:18 PM