From 1b4ca2f219ab44780cbf831467354e050b07028e Mon Sep 17 00:00:00 2001 From: weronika Date: Fri, 17 May 2024 12:27:44 +0200 Subject: [PATCH] install core-js to make working jwt --- App.tsx | 2 ++ package.json | 1 + src/services/TokenService.ts | 13 ++++++++----- yarn.lock | 5 +++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/App.tsx b/App.tsx index a1d3d608..2a69b483 100644 --- a/App.tsx +++ b/App.tsx @@ -4,6 +4,8 @@ // This is added to support web for reaniamted: https://github.com/software-mansion/react-native-reanimated/issues/4140#issuecomment-1455209588 import 'setimmediate' import 'react-native-reanimated' +// This is added to work jwt-decode for react-native: https://github.com/auth0/jwt-decode?tab=readme-ov-file#polyfilling-atob +import 'core-js/stable/atob' // Rest imports import '@baca/i18n' diff --git a/package.json b/package.json index 917ea3c4..01fca498 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "@react-navigation/stack": "^6.3.20", "@tanstack/react-query": "^4.29.19", "axios": "^1.6.7", + "core-js": "^3.37.1", "expo": "~50.0.17", "expo-apple-authentication": "~6.3.0", "expo-application": "~5.8.4", diff --git a/src/services/TokenService.ts b/src/services/TokenService.ts index 40b71e4a..cd18855e 100644 --- a/src/services/TokenService.ts +++ b/src/services/TokenService.ts @@ -1,3 +1,4 @@ +import { AuthControllerRefreshMutationResult } from '@baca/api/query/auth/auth' import { ASYNC_STORAGE_KEYS, ENV } from '@baca/constants' import { decodeAccessToken, secureStore, wait } from '@baca/utils' @@ -72,11 +73,13 @@ export const refreshTokenIfNeeded = async (token: Token): Promise => { if (shouldRefreshToken && !isRefreshingToken) { store.set(isRefreshingTokenAtom, true) - // const refreshedToken: AuthControllerRefreshMutationResult = (await fetch( //FIXME: uncomment this line when type from BE will be improved - const refreshedToken = (await fetch(`${ENV.API_URL}api/v1/auth/refresh`, { - method: 'POST', - headers: { Authorization: `Bearer ${token.refreshToken}` }, - }).then((response) => response.json())) as unknown as Token //FIXME: remove when type from BE will be correct + const refreshedToken: AuthControllerRefreshMutationResult = await fetch( + `${ENV.API_URL}api/v1/auth/refresh`, + { + method: 'POST', + headers: { Authorization: `Bearer ${token.refreshToken}` }, + } + ).then((response) => response.json()) if (token) { await setToken(refreshedToken) diff --git a/yarn.lock b/yarn.lock index 0fded899..6d3f1f00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5435,6 +5435,11 @@ core-js-compat@^3.31.0, core-js-compat@^3.36.1: dependencies: browserslist "^4.23.0" +core-js@^3.37.1: + version "3.37.1" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.37.1.tgz#d21751ddb756518ac5a00e4d66499df981a62db9" + integrity sha512-Xn6qmxrQZyB0FFY8E3bgRXei3lWDJHhvI+u0q9TKIYM49G8pAr0FgnnrFRAmsbptZL1yxRADVXn+x5AGsbBfyw== + core-util-is@~1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"