1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.accountsLink = void 0;
|
4 | var tslib_1 = require("tslib");
|
5 | var context_1 = require("@apollo/client/link/context");
|
6 | var 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 , accountsClientFactory()];
|
14 | case 1:
|
15 | accountsClient = _b.sent();
|
16 | headers = tslib_1.__assign({}, headersWithoutTokens);
|
17 | if (!(req.operationName !== 'refreshTokens')) return [3 , 3];
|
18 | return [4 , 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 , {
|
26 | headers: headers,
|
27 | }];
|
28 | }
|
29 | });
|
30 | });
|
31 | });
|
32 | };
|
33 | exports.accountsLink = accountsLink;
|
34 |
|
\ | No newline at end of file |