로그인 후 앱이 종료되었다가 다시 실행되더라도 로그인이 유지가 되어야 하는 상황
import AsyncStorage from '@react-native-async-storage/async-storage';
import CookieManager from '@react-native-cookies/cookies';
...
// 쿠키 불러오기
const getCookies = async () => {
try {
const cookies =
Platform.OS === 'ios'
? await CookieManager.getAll(true)
: await CookieManager.get(URL);
const exampleCookie = cookies.(쿠키이름).value
// cookies.(실제 쿠키 이름).value 로 값을 불러옴
if(exampleCookie) await AsyncStorage.setItem('저장될 쿠키 이름', exampleCookie);
} catch (error) {
console.error('Failed to get cookies', error);
}
};
// 쿠키 웹뷰와 연동
useEffect(() => {
const loadCookiesAndSetWebView = async () => {
const exampleCookie = await AsyncStorage.getItem('저장될 쿠키 이름')
// WebView에 쿠키를 설정합니다.
if (!exampleCookie) return;
await CookieManager.set(URL, {
name: 'exampleCookie',
value: exampleCookie,
path: '/',
httpOnly: true,
});
};
loadCookiesAndSetWebView();
}, []);