@techstuff-dev/foundation-api-utils 1.17.0 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,24 +35,24 @@ export declare const authSlice: import("@reduxjs/toolkit").Slice<AuthState, {
35
35
  details: {
36
36
  subscription: any;
37
37
  subscriptionDetails: any;
38
- userSub?: string | undefined;
39
- uuid?: string | undefined;
40
- firstName?: string | undefined;
41
- lastName?: string | undefined;
42
- userEmail?: string | undefined;
43
- avatar?: string | undefined;
44
- termsAccepted?: string | undefined;
45
- dateOfBirth?: string | undefined;
46
- contactPreference?: boolean | undefined;
47
- password?: string | undefined;
48
- passwordConfirm?: string | undefined;
49
- agency?: boolean | undefined;
38
+ userSub?: string;
39
+ uuid?: string;
40
+ firstName?: string;
41
+ lastName?: string;
42
+ userEmail?: string;
43
+ picture?: string;
44
+ termsAccepted?: string;
45
+ dateOfBirth?: string;
46
+ contactPreference?: boolean;
47
+ password?: string;
48
+ passwordConfirm?: string;
49
+ agency?: boolean;
50
50
  };
51
51
  accessToken?: string | undefined;
52
52
  idToken?: string | undefined;
53
53
  refreshToken?: string | undefined;
54
54
  expires?: number | undefined;
55
- accessTokenExpiry?: number | null | undefined;
55
+ accessTokenExpiry?: (number | null) | undefined;
56
56
  email?: string | undefined;
57
57
  info?: import("immer").WritableDraft<import("../../types/index.interfaces").Info> | undefined;
58
58
  sub?: string | undefined;
@@ -96,7 +96,7 @@ export declare const authSlice: import("@reduxjs/toolkit").Slice<AuthState, {
96
96
  amount: number;
97
97
  interval: string;
98
98
  currency: string;
99
- cancelAt?: number | undefined;
99
+ cancelAt?: number;
100
100
  planID: string;
101
101
  planDescription: string;
102
102
  paymentDetails: {
@@ -179,7 +179,7 @@ export declare const isAuthenticated: import("reselect").Selector<{
179
179
  amount: number;
180
180
  interval: string;
181
181
  currency: string;
182
- cancelAt?: number | undefined;
182
+ cancelAt?: number;
183
183
  planID: string;
184
184
  planDescription: string;
185
185
  paymentDetails: {
@@ -195,7 +195,7 @@ export declare const isAuthenticated: import("reselect").Selector<{
195
195
  amount: number;
196
196
  interval: string;
197
197
  currency: string;
198
- cancelAt?: number | undefined;
198
+ cancelAt?: number;
199
199
  planID: string;
200
200
  planDescription: string;
201
201
  paymentDetails: {
@@ -13,6 +13,7 @@ interface UserPayload {
13
13
  given_name: string;
14
14
  family_name: string;
15
15
  birthdate: string;
16
+ picture: string;
16
17
  'cognito:username': string;
17
18
  'custom:termsAccepted': string;
18
19
  'custom:subscriptionId': string;
@@ -65,10 +65,10 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
65
65
  }, "error">>)>> & {
66
66
  status: import("@reduxjs/toolkit/query").QueryStatus;
67
67
  }>(arg: DataArgs | typeof import("@reduxjs/toolkit/query").skipToken, options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & {
68
- skip?: boolean | undefined;
69
- refetchOnMountOrArgChange?: number | boolean | undefined;
68
+ skip?: boolean;
69
+ refetchOnMountOrArgChange?: boolean | number;
70
70
  } & {
71
- skip?: boolean | undefined;
71
+ skip?: boolean;
72
72
  selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
73
73
  status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
74
74
  originalArgs?: undefined;
@@ -197,7 +197,7 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
197
197
  }, "error">>)>> & {
198
198
  status: import("@reduxjs/toolkit/query").QueryStatus;
199
199
  }>(options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & Omit<{
200
- skip?: boolean | undefined;
200
+ skip?: boolean;
201
201
  selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
202
202
  status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
203
203
  originalArgs?: undefined;
@@ -261,7 +261,7 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
261
261
  }, "error">>)>> & {
262
262
  status: import("@reduxjs/toolkit/query").QueryStatus;
263
263
  }) => R) | undefined;
264
- }, "skip">) | undefined) => [(arg: DataArgs, preferCacheValue?: boolean | undefined) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<DataArgs, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "Data" | "Workout", ESDataTypes, "contentApi">>, [R][R extends any ? 0 : never], {
264
+ }, "skip">) | undefined) => [(arg: DataArgs, preferCacheValue?: boolean) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<DataArgs, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "Data" | "Workout", ESDataTypes, "contentApi">>, [R][R extends any ? 0 : never], {
265
265
  lastArg: DataArgs;
266
266
  }], useGetDataByIdQuery: <R extends Record<string, any> = import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
267
267
  status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
@@ -326,10 +326,10 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
326
326
  }, "error">>)>> & {
327
327
  status: import("@reduxjs/toolkit/query").QueryStatus;
328
328
  }>(arg: IdArg | typeof import("@reduxjs/toolkit/query").skipToken, options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & {
329
- skip?: boolean | undefined;
330
- refetchOnMountOrArgChange?: number | boolean | undefined;
329
+ skip?: boolean;
330
+ refetchOnMountOrArgChange?: boolean | number;
331
331
  } & {
332
- skip?: boolean | undefined;
332
+ skip?: boolean;
333
333
  selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
334
334
  status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
335
335
  originalArgs?: undefined;
@@ -458,7 +458,7 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
458
458
  }, "error">>)>> & {
459
459
  status: import("@reduxjs/toolkit/query").QueryStatus;
460
460
  }>(options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & Omit<{
461
- skip?: boolean | undefined;
461
+ skip?: boolean;
462
462
  selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
463
463
  status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
464
464
  originalArgs?: undefined;
@@ -522,6 +522,6 @@ export declare const useGetDataQuery: <R extends Record<string, any> = import("@
522
522
  }, "error">>)>> & {
523
523
  status: import("@reduxjs/toolkit/query").QueryStatus;
524
524
  }) => R) | undefined;
525
- }, "skip">) | undefined) => [(arg: IdArg, preferCacheValue?: boolean | undefined) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<IdArg, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "Data" | "Workout", ESDataTypes, "contentApi">>, [R][R extends any ? 0 : never], {
525
+ }, "skip">) | undefined) => [(arg: IdArg, preferCacheValue?: boolean) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<IdArg, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "Data" | "Workout", ESDataTypes, "contentApi">>, [R][R extends any ? 0 : never], {
526
526
  lastArg: IdArg;
527
527
  }];
@@ -68,10 +68,10 @@ export declare const useCheckUserSubscriptionQuery: <R extends Record<string, an
68
68
  }, "error">>)>> & {
69
69
  status: import("@reduxjs/toolkit/query").QueryStatus;
70
70
  }>(arg: UserSubRequest | typeof import("@reduxjs/toolkit/query").skipToken, options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & {
71
- skip?: boolean | undefined;
72
- refetchOnMountOrArgChange?: number | boolean | undefined;
71
+ skip?: boolean;
72
+ refetchOnMountOrArgChange?: boolean | number;
73
73
  } & {
74
- skip?: boolean | undefined;
74
+ skip?: boolean;
75
75
  selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
76
76
  status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
77
77
  originalArgs?: undefined;
@@ -200,7 +200,7 @@ export declare const useCheckUserSubscriptionQuery: <R extends Record<string, an
200
200
  }, "error">>)>> & {
201
201
  status: import("@reduxjs/toolkit/query").QueryStatus;
202
202
  }>(options?: (import("@reduxjs/toolkit/query").SubscriptionOptions & Omit<{
203
- skip?: boolean | undefined;
203
+ skip?: boolean;
204
204
  selectFromResult?: ((state: import("@reduxjs/toolkit/query").TSHelpersId<(Omit<{
205
205
  status: import("@reduxjs/toolkit/query").QueryStatus.uninitialized;
206
206
  originalArgs?: undefined;
@@ -264,6 +264,6 @@ export declare const useCheckUserSubscriptionQuery: <R extends Record<string, an
264
264
  }, "error">>)>> & {
265
265
  status: import("@reduxjs/toolkit/query").QueryStatus;
266
266
  }) => R) | undefined;
267
- }, "skip">) | undefined) => [(arg: UserSubRequest, preferCacheValue?: boolean | undefined) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<UserSubRequest, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "UserSubscription", UserSubResponse, "paymentApi">>, [R][R extends any ? 0 : never], {
267
+ }, "skip">) | undefined) => [(arg: UserSubRequest, preferCacheValue?: boolean) => import("@reduxjs/toolkit/query").QueryActionCreatorResult<import("@reduxjs/toolkit/query").QueryDefinition<UserSubRequest, import("@reduxjs/toolkit/query").BaseQueryFn<string | import("@reduxjs/toolkit/query").FetchArgs, unknown, import("@reduxjs/toolkit/query").FetchBaseQueryError, {}, import("@reduxjs/toolkit/query").FetchBaseQueryMeta>, "UserSubscription", UserSubResponse, "paymentApi">>, [R][R extends any ? 0 : never], {
268
268
  lastArg: UserSubRequest;
269
269
  }];
@@ -1,4 +1,3 @@
1
- /// <reference types="redux-persist/types/persistReducer" />
2
1
  import type { Action, ThunkAction, ThunkDispatch } from '@reduxjs/toolkit';
3
2
  declare const rootReducer: import("@reduxjs/toolkit").CombinedSliceReducer<{
4
3
  auth: import("..").AuthState;
@@ -1,3 +1,2 @@
1
- /// <reference types="redux-persist/types/types" />
2
1
  import { WebStorage } from 'redux-persist/lib/types';
3
2
  export declare function createPersistStorage(): WebStorage;
@@ -47,7 +47,7 @@ export type UserDetails = {
47
47
  firstName?: string;
48
48
  lastName?: string;
49
49
  userEmail?: string;
50
- avatar?: string;
50
+ picture?: string;
51
51
  termsAccepted?: string;
52
52
  dateOfBirth?: string;
53
53
  contactPreference?: boolean;
@@ -185,7 +185,7 @@ export interface UpdateUserRequest {
185
185
  lastName: string;
186
186
  termsAccepted: string;
187
187
  userEmail: string;
188
- avatar?: string;
188
+ picture: string;
189
189
  uuid: string;
190
190
  }
191
191
  export interface UpdateUserResponse {
@@ -318,3 +318,36 @@ export interface PaymentResponse {
318
318
  metadata: {};
319
319
  type: string;
320
320
  }
321
+ export interface DecodedIdToken {
322
+ at_hash: string;
323
+ sub: string;
324
+ 'cognito:groups': string[];
325
+ email_verified: boolean;
326
+ iss: string;
327
+ 'cognito:username': string;
328
+ given_name: string;
329
+ nonce: string;
330
+ aud: string;
331
+ identities: {
332
+ userId: string;
333
+ providerName: string;
334
+ providerType: string;
335
+ issuer: string;
336
+ primary: string;
337
+ dateCreated: string;
338
+ }[];
339
+ token_use: string;
340
+ auth_time: number;
341
+ name: string;
342
+ exp: number;
343
+ iat: number;
344
+ family_name: string;
345
+ email: string;
346
+ birthdate?: string;
347
+ picture?: string;
348
+ }
349
+ export interface SocialTokens {
350
+ accessToken: string;
351
+ idToken: string;
352
+ refreshToken: string;
353
+ }
@@ -1,4 +1,3 @@
1
- import { AuthSession } from '@aws-amplify/core';
2
1
  import { User } from '../../types/index.interfaces';
3
2
  export declare const formatUserPayload: (payload: UserPayload) => {
4
3
  userEmail: string;
@@ -11,6 +10,7 @@ export declare const formatUserPayload: (payload: UserPayload) => {
11
10
  uuid: string;
12
11
  subscription: string | null;
13
12
  customerId: string;
13
+ picture: string;
14
14
  };
15
15
  export declare function formatPromos(data: ESPromo[]): Promo[];
16
16
  export declare function formatWorkout(data: ESWorkout[]): Workout[];
@@ -108,4 +108,4 @@ export declare function formatSchedule(data: ESSchedule[]): Schedule[];
108
108
  export declare function formatChallenges(data: ESChallenge[]): Challenge[];
109
109
  export declare function formatChallengeDays(data: ESChallengeDay[]): ChallengeDay[];
110
110
  export declare function formatSecondsToISO8601Duration(seconds?: number): string;
111
- export declare function formatAuthSession(session: AuthSession): User;
111
+ export declare function formatAuthSession(session: any): User;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { fetchBaseQuery, createApi } from '@reduxjs/toolkit/query/react';
2
- import { fetchAuthSession, signOut } from '@aws-amplify/auth';
2
+ import { Auth } from '@aws-amplify/auth';
3
3
  import { jwtDecode } from 'jwt-decode';
4
4
  import { createSlice, combineSlices, configureStore } from '@reduxjs/toolkit';
5
5
  import { useSelector, useDispatch, useStore } from 'react-redux';
@@ -94,6 +94,7 @@ var initialState = {
94
94
  termsAccepted: '',
95
95
  contactPreference: false,
96
96
  dateOfBirth: '',
97
+ picture: '',
97
98
  },
98
99
  accessToken: '',
99
100
  idToken: '',
@@ -168,8 +169,8 @@ authSlice.reducer;
168
169
 
169
170
  // TODO: typing.
170
171
  var formatUserPayload = function (payload) {
171
- console.log('formatUserPayload', payload);
172
- var userEmail = payload.email, firstName = payload.given_name, lastName = payload.family_name, dateOfBirth = payload.birthdate, uuid = payload["cognito:username"], termsAccepted = payload["custom:termsAccepted"], subscriptionId = payload["custom:subscriptionId"], contactPreference = payload["custom:contactPreferences"], customerId = payload["custom:customerId"];
172
+ console.log('payload', payload);
173
+ var userEmail = payload.email, firstName = payload.given_name, lastName = payload.family_name, dateOfBirth = payload.birthdate, picture = payload.picture, uuid = payload["cognito:username"], termsAccepted = payload["custom:termsAccepted"], subscriptionId = payload["custom:subscriptionId"], contactPreference = payload["custom:contactPreferences"], customerId = payload["custom:customerId"];
173
174
  var parsedTermsAccepted = termsAccepted ? JSON.parse(termsAccepted) : null;
174
175
  var parsedContactPreference = contactPreference
175
176
  ? JSON.parse(contactPreference)
@@ -185,8 +186,8 @@ var formatUserPayload = function (payload) {
185
186
  uuid: uuid,
186
187
  subscription: subscriptionId || null,
187
188
  customerId: customerId,
189
+ picture: picture,
188
190
  };
189
- console.log('formatUserPayload', data);
190
191
  return data;
191
192
  };
192
193
  function formatPromos(data) {
@@ -563,7 +564,8 @@ function formatSecondsToISO8601Duration(seconds) {
563
564
  return duration;
564
565
  }
565
566
  function formatAuthSession(session) {
566
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24;
567
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _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;
568
+ console.log('formatAuthSession session', session);
567
569
  return {
568
570
  accessToken: (_a = session === null || session === void 0 ? void 0 : session.tokens) === null || _a === void 0 ? void 0 : _a.accessToken.toString(),
569
571
  idToken: (_c = (_b = session === null || session === void 0 ? void 0 : session.tokens) === null || _b === void 0 ? void 0 : _b.idToken) === null || _c === void 0 ? void 0 : _c.toString(),
@@ -576,11 +578,12 @@ function formatAuthSession(session) {
576
578
  firstName: (_w = (_v = (_u = (_t = session === null || session === void 0 ? void 0 : session.tokens) === null || _t === void 0 ? void 0 : _t.idToken) === null || _u === void 0 ? void 0 : _u.payload) === null || _v === void 0 ? void 0 : _v.given_name) === null || _w === void 0 ? void 0 : _w.toString(),
577
579
  lastName: (_0 = (_z = (_y = (_x = session === null || session === void 0 ? void 0 : session.tokens) === null || _x === void 0 ? void 0 : _x.idToken) === null || _y === void 0 ? void 0 : _y.payload) === null || _z === void 0 ? void 0 : _z.family_name) === null || _0 === void 0 ? void 0 : _0.toString(),
578
580
  dateOfBirth: (_4 = (_3 = (_2 = (_1 = session === null || session === void 0 ? void 0 : session.tokens) === null || _1 === void 0 ? void 0 : _1.idToken) === null || _2 === void 0 ? void 0 : _2.payload) === null || _3 === void 0 ? void 0 : _3.birthdate) === null || _4 === void 0 ? void 0 : _4.toString(),
579
- 'cognito:username': (_8 = (_7 = (_6 = (_5 = session === null || session === void 0 ? void 0 : session.tokens) === null || _5 === void 0 ? void 0 : _5.idToken) === null || _6 === void 0 ? void 0 : _6.payload) === null || _7 === void 0 ? void 0 : _7['cognito:username']) === null || _8 === void 0 ? void 0 : _8.toString(),
580
- 'custom:termsAccepted': (_12 = (_11 = (_10 = (_9 = session === null || session === void 0 ? void 0 : session.tokens) === null || _9 === void 0 ? void 0 : _9.idToken) === null || _10 === void 0 ? void 0 : _10.payload) === null || _11 === void 0 ? void 0 : _11['custom:termsAccepted']) === null || _12 === void 0 ? void 0 : _12.toString(),
581
- 'custom:subscriptionId': (_16 = (_15 = (_14 = (_13 = session === null || session === void 0 ? void 0 : session.tokens) === null || _13 === void 0 ? void 0 : _13.idToken) === null || _14 === void 0 ? void 0 : _14.payload) === null || _15 === void 0 ? void 0 : _15['custom:subscriptionId']) === null || _16 === void 0 ? void 0 : _16.toString(),
582
- 'custom:contactPreferences': (_20 = (_19 = (_18 = (_17 = session === null || session === void 0 ? void 0 : session.tokens) === null || _17 === void 0 ? void 0 : _17.idToken) === null || _18 === void 0 ? void 0 : _18.payload) === null || _19 === void 0 ? void 0 : _19['custom:contactPreferences']) === null || _20 === void 0 ? void 0 : _20.toString(),
583
- 'custom:customerId': (_24 = (_23 = (_22 = (_21 = session === null || session === void 0 ? void 0 : session.tokens) === null || _21 === void 0 ? void 0 : _21.idToken) === null || _22 === void 0 ? void 0 : _22.payload) === null || _23 === void 0 ? void 0 : _23['custom:customerId']) === null || _24 === void 0 ? void 0 : _24.toString(),
581
+ picture: (_8 = (_7 = (_6 = (_5 = session === null || session === void 0 ? void 0 : session.tokens) === null || _5 === void 0 ? void 0 : _5.idToken) === null || _6 === void 0 ? void 0 : _6.payload) === null || _7 === void 0 ? void 0 : _7.picture) === null || _8 === void 0 ? void 0 : _8.toString(),
582
+ 'cognito:username': (_12 = (_11 = (_10 = (_9 = session === null || session === void 0 ? void 0 : session.tokens) === null || _9 === void 0 ? void 0 : _9.idToken) === null || _10 === void 0 ? void 0 : _10.payload) === null || _11 === void 0 ? void 0 : _11['cognito:username']) === null || _12 === void 0 ? void 0 : _12.toString(),
583
+ 'custom:termsAccepted': (_16 = (_15 = (_14 = (_13 = session === null || session === void 0 ? void 0 : session.tokens) === null || _13 === void 0 ? void 0 : _13.idToken) === null || _14 === void 0 ? void 0 : _14.payload) === null || _15 === void 0 ? void 0 : _15['custom:termsAccepted']) === null || _16 === void 0 ? void 0 : _16.toString(),
584
+ 'custom:subscriptionId': (_20 = (_19 = (_18 = (_17 = session === null || session === void 0 ? void 0 : session.tokens) === null || _17 === void 0 ? void 0 : _17.idToken) === null || _18 === void 0 ? void 0 : _18.payload) === null || _19 === void 0 ? void 0 : _19['custom:subscriptionId']) === null || _20 === void 0 ? void 0 : _20.toString(),
585
+ 'custom:contactPreferences': (_24 = (_23 = (_22 = (_21 = session === null || session === void 0 ? void 0 : session.tokens) === null || _21 === void 0 ? void 0 : _21.idToken) === null || _22 === void 0 ? void 0 : _22.payload) === null || _23 === void 0 ? void 0 : _23['custom:contactPreferences']) === null || _24 === void 0 ? void 0 : _24.toString(),
586
+ 'custom:customerId': (_28 = (_27 = (_26 = (_25 = session === null || session === void 0 ? void 0 : session.tokens) === null || _25 === void 0 ? void 0 : _25.idToken) === null || _26 === void 0 ? void 0 : _26.payload) === null || _27 === void 0 ? void 0 : _27['custom:customerId']) === null || _28 === void 0 ? void 0 : _28.toString(),
584
587
  },
585
588
  };
586
589
  }
@@ -623,17 +626,19 @@ var APP_ES_AUTH = ((_f = process.env) === null || _f === void 0 ? void 0 : _f.NE
623
626
  var authDataBaseQuery = fetchBaseQuery({
624
627
  baseUrl: API_AUTH_PREFIX,
625
628
  prepareHeaders: function (headers_1, _a) { return __awaiter(void 0, [headers_1, _a], void 0, function (headers, _b) {
626
- var tokens;
629
+ var session, idToken, accessToken;
627
630
  return __generator(this, function (_c) {
628
631
  switch (_c.label) {
629
632
  case 0:
630
633
  headers.set('Content-Type', 'application/json');
631
- return [4 /*yield*/, fetchAuthSession()];
634
+ return [4 /*yield*/, Auth.currentSession()];
632
635
  case 1:
633
- tokens = (_c.sent()).tokens;
634
- if ((tokens === null || tokens === void 0 ? void 0 : tokens.accessToken) && tokens.idToken) {
635
- headers.set('accesstoken', tokens.accessToken.toString());
636
- headers.set('idtoken', tokens.idToken.toString());
636
+ session = _c.sent();
637
+ idToken = session.getIdToken().getJwtToken();
638
+ accessToken = session.getAccessToken().getJwtToken();
639
+ if (accessToken && idToken) {
640
+ headers.set('accesstoken', accessToken);
641
+ headers.set('idtoken', idToken);
637
642
  // headers.set('refreshtoken', tokens.refreshToken);
638
643
  }
639
644
  return [2 /*return*/, headers];
@@ -654,9 +659,12 @@ var authDataBaseQueryWithReauth = function (args, api, extraOptions) { return __
654
659
  case 1:
655
660
  result = _b.sent();
656
661
  if (!(((_a = result === null || result === void 0 ? void 0 : result.error) === null || _a === void 0 ? void 0 : _a.status) === 401)) return [3 /*break*/, 6];
657
- return [4 /*yield*/, fetchAuthSession()];
662
+ return [4 /*yield*/, Auth.currentAuthenticatedUser({
663
+ bypassCache: true, // Ensures that the user is refreshed from the server
664
+ })];
658
665
  case 2:
659
666
  authSession = _b.sent();
667
+ console.log('Session successfully refreshed:', authSession);
660
668
  user = formatAuthSession(authSession);
661
669
  api.dispatch(setCredentials(user));
662
670
  if (!(authSession === null || authSession === void 0 ? void 0 : authSession.tokens)) return [3 /*break*/, 4];
@@ -667,7 +675,7 @@ var authDataBaseQueryWithReauth = function (args, api, extraOptions) { return __
667
675
  return [3 /*break*/, 6];
668
676
  case 4:
669
677
  // TODO; require full data reset?
670
- return [4 /*yield*/, signOut()];
678
+ return [4 /*yield*/, Auth.signOut()];
671
679
  case 5:
672
680
  // TODO; require full data reset?
673
681
  _b.sent();