Skip to content
This repository was archived by the owner on Jan 24, 2020. It is now read-only.

Commit fd59d1c

Browse files
Omer Lachish-Rauchwergerjoeferraro
authored andcommitted
Support for clearing a single cookie by name (#32)
* clear a single cookie * mistakenly renamed an export function name * indicate the clearByName is iOS only
1 parent cacc910 commit fd59d1c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ CookieManager.clearAll((err, res) => {
5656
console.log(res);
5757
});
5858

59+
// clear a specific cookie by its name (IOS ONLY)
60+
CookieManager.clearByName('cookie_name', (err, res) => {
61+
console.log('cookie cleared!');
62+
console.log(err);
63+
console.log(res);
64+
});
65+
5966
```
6067

6168
### Roadmap

RNCookieManagerIOS/RNCookieManagerIOS.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ @implementation RNCookieManagerIOS
5555
callback(@[[NSNull null]]);
5656
}
5757

58+
RCT_EXPORT_METHOD(clearByName:(NSString *)name callback:(RCTResponseSenderBlock)callback) {
59+
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
60+
for (NSHTTPCookie *c in cookieStorage.cookies) {
61+
if ([[c name] isEqualToString:name]) {
62+
[cookieStorage deleteCookie:c];
63+
}
64+
}
65+
callback(@[[NSNull null]]);
66+
}
67+
5868
// TODO: return a better formatted list of cookies per domain
5969
RCT_EXPORT_METHOD(getAll:(RCTResponseSenderBlock)callback) {
6070
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var functions = [
2121
'setFromResponse',
2222
'get',
2323
'getAll',
24-
'clearAll'
24+
'clearAll',
25+
'clearByName'
2526
];
2627

2728
module.exports = {}

0 commit comments

Comments
 (0)