-
Notifications
You must be signed in to change notification settings - Fork 0
/
apollo.js
92 lines (81 loc) · 2.4 KB
/
apollo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { ApolloClient, InMemoryCache, makeVar } from "@apollo/client";
import { setContext } from "@apollo/client/link/context";
import { createUploadLink } from "apollo-upload-client";
import axios from "axios";
import Cookies from "js-cookie";
const TOKEN = "TOKEN";
const isLoggedIn = typeof window !== "undefined" && Boolean(Cookies.get(TOKEN));
export const isLoggedInVar = makeVar(isLoggedIn);
export const logUserIn = (token) => {
Cookies.set("authorization", "true");
Cookies.set(TOKEN, token, { expires: 1 });
isLoggedInVar(true);
};
export const logUserOut = () => {
Cookies.set("authorization", "false");
Cookies.remove(TOKEN);
window.location.replace("/");
};
export async function purgeAllUsers() {
await axios.post(
process.env.NODE_ENV === "production"
? "https://admin.stellate.co/dics-management"
: "http://localhost:3011/",
JSON.stringify({ query: `mutation { purgeUser }` }),
{
headers: {
"Content-Type": "application/json",
"stellate-token":
"57ceed6f1995880253b2950d0951c7e878b6c01dd9e829af47204f8751c36b9c",
},
}
);
}
export async function purgeAllPhotos() {
await axios.post(
process.env.NODE_ENV === "production"
? "https://admin.stellate.co/dics-management"
: "http://localhost:3011/",
JSON.stringify({ query: `mutation { purgePhoto }` }),
{
headers: {
"Content-Type": "application/json",
"stellate-token":
"57ceed6f1995880253b2950d0951c7e878b6c01dd9e829af47204f8751c36b9c",
},
}
);
}
export async function purgeAllScores() {
await axios.post(
process.env.NODE_ENV === "production"
? "https://admin.stellate.co/dics-management"
: "http://localhost:3011/",
JSON.stringify({ query: `mutation { purgeScore }` }),
{
headers: {
"Content-Type": "application/json",
"stellate-token":
"57ceed6f1995880253b2950d0951c7e878b6c01dd9e829af47204f8751c36b9c",
},
}
);
}
const uploadHttpLink = createUploadLink({
uri:
process.env.NODE_ENV === "production"
? "https://dics-management.stellate.sh"
: "http://localhost:4000/graphql",
});
const authLink = setContext((_, { headers }) => {
return {
headers: {
...headers,
"x-jwt": Cookies.get(TOKEN),
},
};
});
export const client = new ApolloClient({
link: authLink.concat(uploadHttpLink),
cache: new InMemoryCache(),
});