File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed
android/src/main/java/com/reactnativecommunity/cookies Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,16 @@ CookieManager.flush()
117117 .then ((success ) => {
118118 console .log (' CookieManager.flush =>' , success);
119119 });
120+
121+ // Remove session cookies (ANDROID ONLY)
122+ // Session cookies are cookies with no expires set. Android typically does not
123+ // remove these, it is up to the developer to decide when to remove them.
124+ // The return value is true if any session cookies were removed.
125+ // iOS handles removal of session cookies automatically on app open.
126+ CookieManager .removeSessionCookies ()
127+ .then ((sessionCookiesRemoved ) => {
128+ console .log (' CookieManager.removeSessionCookies =>' , sessionCookiesRemoved);
129+ });
120130```
121131
122132### WebKit-Support (iOS only)
Original file line number Diff line number Diff line change @@ -102,6 +102,20 @@ public void flush(Promise promise) {
102102 }
103103 }
104104
105+ @ ReactMethod
106+ public void removeSessionCookies (Promise promise ) {
107+ try {
108+ getCookieManager ().removeSessionCookies (new ValueCallback <Boolean >() {
109+ @ Override
110+ public void onReceiveValue (Boolean data ) {
111+ promise .resolve (data );
112+ }
113+ });
114+ } catch (Exception e ) {
115+ promise .reject (e );
116+ }
117+ }
118+
105119 @ ReactMethod
106120 public void getFromResponse (String url , Promise promise ) throws URISyntaxException , IOException {
107121 promise .resolve (url );
Original file line number Diff line number Diff line change @@ -23,9 +23,11 @@ declare module '@react-native-cookies/cookies' {
2323
2424 clearAll ( useWebKit ?: boolean ) : Promise < boolean > ;
2525
26+ // Android only
2627 flush ( ) : Promise < void > ;
28+ removeSessionCookies ( ) : Promise < boolean > ;
2729
28- //iOS only
30+ // iOS only
2931 getAll ( useWebKit ?: boolean ) : Promise < Cookies > ;
3032 clearByName (
3133 url : string ,
Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ module.exports = {
4646 await CookieManager . flush ( ) ;
4747 }
4848 } ,
49+ removeSessionCookies : async ( ) => {
50+ if ( Platform . OS === 'android' ) {
51+ return await CookieManager . removeSessionCookies ( ) ;
52+ }
53+ } ,
4954} ;
5055
5156for ( var i = 0 ; i < functions . length ; i ++ ) {
You can’t perform that action at this time.
0 commit comments