Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into macos-support

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
  • Loading branch information
tyfyakov21 committed Jun 28, 2022
2 parents cb2000e + 69fe655 commit 7473071
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 86 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ This module was ported from [joeferraro/react-native-cookies](https://github.com

## Maintainers

- [Jason Safaiyeh](https://github.com/safaiyeh) ([Twitter @safaiyeh](https://twitter.com/safaiyeh)) from [Sumo Logic](https://www.sumologic.com)
- [Jason Safaiyeh](https://github.com/safaiyeh) ([Twitter @safaiyeh](https://twitter.com/safaiyeh)) from [🪄 Magic Eden](https://magiceden.io)

## Platforms Supported

✅ iOS
✅ Android
❌ Expo is working on their own cookie support (https://github.com/expo/expo/issues/6756)
- ✅ iOS
- ✅ Android
- ❌ Currently lacking support for Windows, macOS, and web. Support for these platforms will be created when there is a need for them. Starts with a posted issue.

Currently lacking support for Windows, macOS, and web. Support for these platforms will be created when there is a need for them. Starts with a posted issue.
## Expo

- ✅ You can use this library with [Development Builds](https://docs.expo.dev/development/introduction/). No config plugin is required.
- ❌ This library can't be used in the "Expo Go" app because it [requires custom native code](https://docs.expo.dev/workflow/customizing/).

## Installation

Expand Down Expand Up @@ -117,6 +120,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
70 changes: 1 addition & 69 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import groovy.json.JsonSlurper


// android/build.gradle

Expand All @@ -22,7 +22,6 @@ def safeExtGet(prop, fallback) {
}

apply plugin: 'com.android.library'
apply plugin: 'maven'

buildscript {
// The Android Gradle plugin is only required when opening the android folder stand-alone.
Expand All @@ -41,7 +40,6 @@ buildscript {
}

apply plugin: 'com.android.library'
apply plugin: 'maven'

android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
Expand Down Expand Up @@ -76,69 +74,3 @@ dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
}

def configureReactNativePom(def pom) {
def packageJson = new JsonSlurper().parseText(file('../package.json').text)

pom.project {
name packageJson.title
artifactId packageJson.name
version = packageJson.version
group = "com.reactlibrary"
description packageJson.description
url packageJson.repository.baseUrl

licenses {
license {
name packageJson.license
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
distribution 'repo'
}
}
}
}

afterEvaluate { project ->
// some Gradle build hooks ref:
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
task androidJavadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += files(android.bootClasspath)
classpath += files(project.getConfigurations().getByName('compile').asList())
include '**/*.java'
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
include '**/*.java'
}

android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
def javaCompileTask = variant.javaCompileProvider.get()

task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
from javaCompileTask.destinationDir
}
}

artifacts {
archives androidSourcesJar
archives androidJavadocJar
}

task installArchives(type: Upload) {
configuration = configurations.archives
repositories.mavenDeployer {
// Deploy to react-native-event-bridge/maven, ready to publish to npm
repository url: "file://${projectDir}/../android/maven"
configureReactNativePom pom
}
}
}
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(final 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 @@ -53,6 +53,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
4 changes: 0 additions & 4 deletions ios/RNCookieManagerIOS/RNCookieManagerIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
* LICENSE file here: https://github.com/joeferraro/react-native-cookies/blob/master/LICENSE.md.
*/

#if __has_include("RCTBridgeModule.h")
#import "RCTBridgeModule.h"
#else
#import <React/RCTBridgeModule.h>
#endif

#import <WebKit/WebKit.h>

Expand Down
18 changes: 12 additions & 6 deletions ios/RNCookieManagerIOS/RNCookieManagerIOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
*/

#import "RNCookieManagerIOS.h"
#if __has_include("RCTConvert.h")
#import "RCTConvert.h"
#else
#import <React/RCTConvert.h>
#endif

static NSString * const NOT_AVAILABLE_ERROR_MESSAGE = @"WebKit/WebKit-Components are only available with iOS11 and higher!";
static NSString * const INVALID_URL_MISSING_HTTP = @"Invalid URL: It may be missing a protocol (ex. http:// or https://).";
Expand Down Expand Up @@ -199,7 +195,7 @@ + (BOOL)requiresMainQueueSetup
WKHTTPCookieStore *cookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
[cookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *allCookies) {
for (NSHTTPCookie *cookie in allCookies) {
if ([name isEqualToString:cookie.name]) {
if ([name isEqualToString:cookie.name] && [self isMatchingDomain:topLevelDomain cookieDomain:cookie.domain]) {
[foundCookiesList addObject:cookie];
foundCookies = @YES;
}
Expand All @@ -216,7 +212,7 @@ + (BOOL)requiresMainQueueSetup
} else {
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *c in cookieStorage.cookies) {
if ([[c name] isEqualToString:name]) {
if ([[c name] isEqualToString:name] && [self isMatchingDomain:url.host cookieDomain:c.domain]) {
[cookieStorage deleteCookie:c];
foundCookies = @YES;
}
Expand Down Expand Up @@ -341,4 +337,14 @@ -(NSDictionary *)createCookieData:(NSHTTPCookie *)cookie
return cookieData;
}

-(BOOL)isMatchingDomain:(NSString *)originDomain
cookieDomain:(NSString *)cookieDomain
{
if ([originDomain isEqualToString: cookieDomain]) {
return @YES;
}
NSString *parentDomain = [cookieDomain hasPrefix:@"."] ? cookieDomain : [@"." stringByAppendingString: cookieDomain];
return [originDomain hasSuffix:parentDomain];
}

@end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-cookies/cookies",
"version": "6.0.10",
"version": "6.2.1",
"description": "Cookie Manager for React Native",
"repository": {
"type": "git",
Expand Down

0 comments on commit 7473071

Please sign in to comment.