import CookieManager from '@react-native-cookies/cookies';
import Constants from 'expo-constants';
const webUrl = Constants.expoConfig?.extra?.apiBaseUrl as string;
export const cookieStorage = {
async setRefreshToken(refreshToken: string) {
try {
await CookieManager.setFromResponse(webUrl, refreshToken);
} catch {
throw new Error('Failed to store refresh token in cookies');
}
},
async getRefreshToken(): Promise<string | null> {
try {
const cookies = await CookieManager.get(webUrl);
return cookies.refresh?.value ?? null;
} catch {
return null;
}
},
async removeRefreshToken() {
await CookieManager.clearByName(webUrl, 'refresh');
},
};