summaryrefslogtreecommitdiffstats
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/components/Signin.js2
-rw-r--r--frontend/components/Signout.js17
-rw-r--r--frontend/components/Signup.js2
-rw-r--r--frontend/lib/withData.js19
-rw-r--r--frontend/queries/queries.graphql6
5 files changed, 23 insertions, 23 deletions
diff --git a/frontend/components/Signin.js b/frontend/components/Signin.js
index f719c60..7a4db8c 100644
--- a/frontend/components/Signin.js
+++ b/frontend/components/Signin.js
@@ -13,7 +13,7 @@ class Signin extends Component {
loginUser = async (e, signin, client) => {
e.preventDefault();
const res = await signin();
- localStorage.setItem('token', res.data.signin.token);
+ // TODO instead of refetching, can we just use the data returned?
client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' });
};
diff --git a/frontend/components/Signout.js b/frontend/components/Signout.js
index 4ef8e6c..fbd7fd9 100644
--- a/frontend/components/Signout.js
+++ b/frontend/components/Signout.js
@@ -1,20 +1,13 @@
import React, { Component } from 'react';
-import { Query } from 'react-apollo';
-import { CURRENT_USER_QUERY } from '../queries/queries.graphql';
+import { Query, Mutation } from 'react-apollo';
+import { CURRENT_USER_QUERY, SIGN_OUT_MUTATION } from '../queries/queries.graphql';
class Signout extends Component {
- signout = refetch => {
- console.log(refetch);
- console.log('Signing Out');
- localStorage.removeItem('token');
- refetch();
- };
-
render() {
return (
- <Query query={CURRENT_USER_QUERY}>
- {({ refetch }) => <button onClick={() => this.signout(refetch)}>Sign Out</button>}
- </Query>
+ <Mutation mutation={SIGN_OUT_MUTATION} refetchQueries={[{ query: CURRENT_USER_QUERY }]}>
+ {signout => <button onClick={signout}>Sign Out</button>}
+ </Mutation>
);
}
}
diff --git a/frontend/components/Signup.js b/frontend/components/Signup.js
index e8c639b..22a729f 100644
--- a/frontend/components/Signup.js
+++ b/frontend/components/Signup.js
@@ -26,7 +26,7 @@ class Signup extends Component {
onSubmit={async e => {
e.preventDefault();
const res = await signup();
- localStorage.setItem('token', res.data.signup.token);
+ // TODO can we return theuser from signup?
client.query({ query: CURRENT_USER_QUERY, fetchPolicy: 'network-only' });
}}
>
diff --git a/frontend/lib/withData.js b/frontend/lib/withData.js
index 9f7c2a8..0696333 100644
--- a/frontend/lib/withData.js
+++ b/frontend/lib/withData.js
@@ -6,15 +6,16 @@ import { LOCAL_STATE_QUERY } from '../queries/queries.graphql';
const client = new ApolloClient({
uri: process.env.NODE_ENV === 'development' ? 'http://localhost:4444' : 'http://localhost:4444',
ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)
- request: operation => {
- // if we're in the client and the user has a token, send it along with the request
- if (typeof localStorage !== 'undefined' && localStorage.getItem('token')) {
- operation.setContext({
- headers: {
- authorization: `Bearer ${localStorage.getItem('token')}`,
- },
- });
- }
+ // TODO this is a bug: https://github.com/apollographql/apollo-client/issues/3265
+ fetchOptions: {
+ credentials: 'include',
+ },
+ request: async operation => {
+ operation.setContext({
+ fetchOptions: {
+ credentials: 'include',
+ },
+ });
},
clientState: {
resolvers: {
diff --git a/frontend/queries/queries.graphql b/frontend/queries/queries.graphql
index 61d5587..22e5f29 100644
--- a/frontend/queries/queries.graphql
+++ b/frontend/queries/queries.graphql
@@ -36,6 +36,12 @@ mutation SIGNIN_MUTATION($email: String!, $password: String!) {
}
}
+mutation SIGN_OUT_MUTATION {
+ signout {
+ id
+ }
+}
+
mutation REQUEST_RESET_MUTATION($email: String!) {
requestReset(email: $email) {
id