UNPKG

1.49 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.accountsLink = void 0;
4var tslib_1 = require("tslib");
5var context_1 = require("@apollo/client/link/context");
6var accountsLink = function (accountsClientFactory) {
7 return context_1.setContext(function (req, _a) {
8 var headersWithoutTokens = _a.headers;
9 return tslib_1.__awaiter(void 0, void 0, void 0, function () {
10 var accountsClient, headers, tokens;
11 return tslib_1.__generator(this, function (_b) {
12 switch (_b.label) {
13 case 0: return [4 /*yield*/, accountsClientFactory()];
14 case 1:
15 accountsClient = _b.sent();
16 headers = tslib_1.__assign({}, headersWithoutTokens);
17 if (!(req.operationName !== 'refreshTokens')) return [3 /*break*/, 3];
18 return [4 /*yield*/, accountsClient.refreshSession()];
19 case 2:
20 tokens = _b.sent();
21 if (tokens) {
22 headers.Authorization = 'Bearer ' + tokens.accessToken;
23 }
24 _b.label = 3;
25 case 3: return [2 /*return*/, {
26 headers: headers,
27 }];
28 }
29 });
30 });
31 });
32};
33exports.accountsLink = accountsLink;
34//# sourceMappingURL=index.js.map
\No newline at end of file