Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Comment on lines +106 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to flush here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not flush, sync*

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've seen so far, we didn't have to do a flush or sync or anything else to get fetch or a webview to get rid of these session cookies. We've just been using this call and the next fetch we do results in the session cookies no longer being there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg! lets ship it


@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