Skip to content

Commit

Permalink
feat: Updates headers sent from frontend package
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshnirmalya committed Apr 4, 2020
1 parent f55f04f commit eb72365
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/frontend/lib/init-apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ if (!process.browser) {

const httpApiUrl = process.env.API_URL || "";
const wsApiUrl = process.env.WS_URL || "";
const token = cookieParser("token");
const userId = cookieParser("user-id");
const userRoles = cookieParser("user-roles");
const headers = {
"X-Hasura-API-Token": `Bearer ${token}`,
"X-Hasura-Admin-Secret": process.env.HASURA_ADMIN_SECRET,
"X-Hasura-User-ID": userId,
"X-Hasura-User-Roles": [userRoles],
};

function create() {
const token = cookieParser("token");

const httpLink = new HttpLink({
uri: httpApiUrl,
credentials: "include",
headers: {
Authorization: `Bearer ${token}`,
"x-hasura-admin-secret": process.env.HASURA_ADMIN_SECRET,
},
headers,
});

const wsLink = process.browser
Expand All @@ -34,10 +40,7 @@ function create() {
options: {
reconnect: true,
connectionParams: {
headers: {
Authorization: `Bearer ${token}`,
"x-hasura-admin-secret": process.env.HASURA_ADMIN_SECRET,
},
headers,
},
},
})
Expand Down

0 comments on commit eb72365

Please sign in to comment.