react-native-cookies icon indicating copy to clipboard operation
react-native-cookies copied to clipboard

Validate cookie properties in the set method, with more meaningful error messages

Open dlajarretie opened this issue 7 years ago • 3 comments

According to Apple doc :

To successfully create a cookie, you must provide values for (at least) the NSHTTPCookiePath, NSHTTPCookieName, and NSHTTPCookieValue keys, and either the NSHTTPCookieOriginURL key or the NSHTTPCookieDomain key.

I have therefore added some checks to validate that the provided cookie properties match these requirements. This has the added benefit of allowing the creation of cookies when providing only the required properties.

Also took advantage of promises reject blocks to fail cleanly, with meaningful errors that can be caught directly in JS without crashing the native code.

dlajarretie avatar Nov 07 '17 17:11 dlajarretie

with this PR, is it possible to set a session-only cookie by not having expiration date?

ravelab avatar Dec 08 '17 01:12 ravelab

It will be possible indeed (only for iOS though, I don't know if the Android implementation allows this already).

dlajarretie avatar Dec 08 '17 09:12 dlajarretie

I have forked the repo here: https://github.com/safaiyeh/react-native-cookie-store We can create issues and PRs there to continue the development of the project.

safaiyeh avatar Dec 11 '19 20:12 safaiyeh