initial: add login
This commit is contained in:
30
utils/storage.ts
Normal file
30
utils/storage.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
|
||||
export async function setStorageItem(
|
||||
key: string,
|
||||
value: string
|
||||
): Promise<void> {
|
||||
try {
|
||||
await AsyncStorage.setItem(key, value);
|
||||
} catch (error) {
|
||||
console.error("Error setting storage item:", error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStorageItem(key: string): Promise<string | null> {
|
||||
try {
|
||||
const value = await AsyncStorage.getItem(key);
|
||||
return value;
|
||||
} catch (error) {
|
||||
console.error("Error getting storage item:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function removeStorageItem(key: string): Promise<void> {
|
||||
try {
|
||||
await AsyncStorage.removeItem(key);
|
||||
} catch (error) {
|
||||
console.error("Error removing storage item:", error);
|
||||
}
|
||||
}
|
||||
13
utils/token.ts
Normal file
13
utils/token.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export function parseJwtToken(token: string) {
|
||||
if (!token) return null;
|
||||
|
||||
const base64Url = token.split('.')[1];
|
||||
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
||||
const jsonPayload = decodeURIComponent(
|
||||
atob(base64)
|
||||
.split('')
|
||||
.map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
||||
.join(''),
|
||||
);
|
||||
return JSON.parse(jsonPayload);
|
||||
}
|
||||
Reference in New Issue
Block a user