Skip to content

Commit

Permalink
feat(Android): Implement Android's removeSessionCookies method (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
astapinski authored Apr 18, 2022
1 parent 167edee commit b459739
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ CookieManager.flush()
.then((success) => {
console.log('CookieManager.flush =>', success);
});

// Remove session cookies (ANDROID ONLY)
// Session cookies are cookies with no expires set. Android typically does not
// remove these, it is up to the developer to decide when to remove them.
// The return value is true if any session cookies were removed.
// iOS handles removal of session cookies automatically on app open.
CookieManager.removeSessionCookies()
.then((sessionCookiesRemoved) => {
console.log('CookieManager.removeSessionCookies =>', sessionCookiesRemoved);
});
```

### WebKit-Support (iOS only)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ public void flush(Promise promise) {
}
}

@ReactMethod
public void removeSessionCookies(Promise promise) {
try {
getCookieManager().removeSessionCookies(new ValueCallback<Boolean>() {
@Override
public void onReceiveValue(Boolean data) {
promise.resolve(data);
}
});
} catch (Exception e) {
promise.reject(e);
}
}

@ReactMethod
public void getFromResponse(String url, Promise promise) throws URISyntaxException, IOException {
promise.resolve(url);
Expand Down
4 changes: 3 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ declare module '@react-native-cookies/cookies' {

clearAll(useWebKit?: boolean): Promise<boolean>;

// Android only
flush(): Promise<void>;
removeSessionCookies(): Promise<boolean>;

//iOS only
// iOS only
getAll(useWebKit?: boolean): Promise<Cookies>;
clearByName(
url: string,
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ module.exports = {
await CookieManager.flush();
}
},
removeSessionCookies: async () => {
if (Platform.OS === 'android') {
return await CookieManager.removeSessionCookies();
}
},
};

for (var i = 0; i < functions.length; i++) {
Expand Down

0 comments on commit b459739

Please sign in to comment.