Skip to content

Commit 3b9bc09

Browse files
TabbyTschucki
andauthored
feat: add react-native-web support (#1)
* feat: add `react-native-web` support * ci: remove packageManager field from package.json (#2) --------- Co-authored-by: Marcel <marceldjnairo@gmail.com>
1 parent 6d6f9bf commit 3b9bc09

File tree

4 files changed

+275
-351
lines changed

4 files changed

+275
-351
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
]
155155
},
156156
"dependencies": {
157+
"@react-native-async-storage/async-storage": "^1.21.0",
157158
"expo-secure-store": "^12.3.1"
158159
}
159160
}

src/utils/TokenStorage.native.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as SecureStore from 'expo-secure-store';
2+
3+
class TokenStorage {
4+
private static readonly TOKEN_KEY = 'authToken';
5+
6+
static async saveToken(token: string): Promise<void> {
7+
try {
8+
await SecureStore.setItemAsync(TokenStorage.TOKEN_KEY, token);
9+
} catch (error) {
10+
console.error('Error while saving the encrypted token:', error);
11+
throw error;
12+
}
13+
}
14+
15+
static async getToken(): Promise<string | null> {
16+
try {
17+
const encryptedToken = await SecureStore.getItemAsync(
18+
TokenStorage.TOKEN_KEY
19+
);
20+
return encryptedToken || null;
21+
} catch (error) {
22+
console.error('Error while retrieving the encrypted token:', error);
23+
throw error;
24+
}
25+
}
26+
27+
static async removeToken(): Promise<void> {
28+
try {
29+
await SecureStore.deleteItemAsync(TokenStorage.TOKEN_KEY);
30+
} catch (error) {
31+
console.error('Error while removing the encrypted token:', error);
32+
throw error;
33+
}
34+
}
35+
}
36+
37+
export default TokenStorage;

src/utils/TokenStorage.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as SecureStore from 'expo-secure-store';
1+
import AsyncStorage from '@react-native-async-storage/async-storage';
22

33
class TokenStorage {
44
private static readonly TOKEN_KEY = 'authToken';
55

66
static async saveToken(token: string): Promise<void> {
77
try {
8-
await SecureStore.setItemAsync(TokenStorage.TOKEN_KEY, token);
8+
await AsyncStorage.setItem(TokenStorage.TOKEN_KEY, token);
99
} catch (error) {
1010
console.error('Error while saving the encrypted token:', error);
1111
throw error;
@@ -14,10 +14,8 @@ class TokenStorage {
1414

1515
static async getToken(): Promise<string | null> {
1616
try {
17-
const encryptedToken = await SecureStore.getItemAsync(
18-
TokenStorage.TOKEN_KEY
19-
);
20-
return encryptedToken || null;
17+
const localToken = await AsyncStorage.getItem(TokenStorage.TOKEN_KEY);
18+
return localToken || null;
2119
} catch (error) {
2220
console.error('Error while retrieving the encrypted token:', error);
2321
throw error;
@@ -26,7 +24,7 @@ class TokenStorage {
2624

2725
static async removeToken(): Promise<void> {
2826
try {
29-
await SecureStore.deleteItemAsync(TokenStorage.TOKEN_KEY);
27+
await AsyncStorage.removeItem(TokenStorage.TOKEN_KEY);
3028
} catch (error) {
3129
console.error('Error while removing the encrypted token:', error);
3230
throw error;

0 commit comments

Comments
 (0)