Skip to content

Commit 0d8fdc4

Browse files
Merge pull request #58 from binarapps/fix/refresh-token
Fix/refresh token
2 parents c0c4822 + 1b4ca2f commit 0d8fdc4

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// This is added to support web for reaniamted: https://github.com/software-mansion/react-native-reanimated/issues/4140#issuecomment-1455209588
55
import 'setimmediate'
66
import 'react-native-reanimated'
7+
// This is added to work jwt-decode for react-native: https://github.com/auth0/jwt-decode?tab=readme-ov-file#polyfilling-atob
8+
import 'core-js/stable/atob'
79

810
// Rest imports
911
import '@baca/i18n'

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"@react-navigation/stack": "^6.3.20",
109109
"@tanstack/react-query": "^4.29.19",
110110
"axios": "^1.6.7",
111+
"core-js": "^3.37.1",
111112
"expo": "~50.0.17",
112113
"expo-apple-authentication": "~6.3.0",
113114
"expo-application": "~5.8.4",

src/services/TokenService.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AuthControllerRefreshMutationResult } from '@baca/api/query/auth/auth'
12
import { ASYNC_STORAGE_KEYS, ENV } from '@baca/constants'
23
import { decodeAccessToken, secureStore, wait } from '@baca/utils'
34

@@ -72,11 +73,13 @@ export const refreshTokenIfNeeded = async (token: Token): Promise<Token> => {
7273
if (shouldRefreshToken && !isRefreshingToken) {
7374
store.set(isRefreshingTokenAtom, true)
7475

75-
// const refreshedToken: AuthControllerRefreshMutationResult = (await fetch( //FIXME: uncomment this line when type from BE will be improved
76-
const refreshedToken = (await fetch(`${ENV.API_URL}api/v1/auth/refresh`, {
77-
method: 'POST',
78-
headers: { Authorization: `Bearer ${token.refreshToken}` },
79-
}).then((response) => response.json())) as unknown as Token //FIXME: remove when type from BE will be correct
76+
const refreshedToken: AuthControllerRefreshMutationResult = await fetch(
77+
`${ENV.API_URL}api/v1/auth/refresh`,
78+
{
79+
method: 'POST',
80+
headers: { Authorization: `Bearer ${token.refreshToken}` },
81+
}
82+
).then((response) => response.json())
8083

8184
if (token) {
8285
await setToken(refreshedToken)

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5435,6 +5435,11 @@ core-js-compat@^3.31.0, core-js-compat@^3.36.1:
54355435
dependencies:
54365436
browserslist "^4.23.0"
54375437

5438+
core-js@^3.37.1:
5439+
version "3.37.1"
5440+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.37.1.tgz#d21751ddb756518ac5a00e4d66499df981a62db9"
5441+
integrity sha512-Xn6qmxrQZyB0FFY8E3bgRXei3lWDJHhvI+u0q9TKIYM49G8pAr0FgnnrFRAmsbptZL1yxRADVXn+x5AGsbBfyw==
5442+
54385443
core-util-is@~1.0.0:
54395444
version "1.0.3"
54405445
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"

0 commit comments

Comments
 (0)