bugfix issue#68

This commit is contained in:
Rick van Lieshout 2020-05-26 17:16:01 +02:00
parent 22bb46981d
commit e7c2b5b39a
4 changed files with 62 additions and 41 deletions

View File

@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [5.0.1]
- Fixed [Issue
69](https://github.com/Mastermindzh/react-cookie-consent/issues/69) by
removing location from the proptypes to avoid build-time issues
## [5.0.0]
### added
- CookieSecurity prop - allows securing the cookie
- sameSite prop - allows you to set sameSite properties so browser won't warn
about non-secure cookies :)
## [4.1.0]
### changed

View File

@ -90,7 +90,7 @@ If the decline button is enabled then the (onDecline) prop function can be used,
## Props
| Prop | Type | Default value | Description |
| ------------------------ | :-------------------------------: | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| ------------------------ | :-------------------------------: | ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| location | string, "top", "bottom" or "none" | "bottom" | Syntactic sugar to easily enable you to place the bar at the top or the bottom of the browser window. Use "none" to disable. |
| children | string or React component | | Content to appear inside the bar |
| disableStyles | boolean | false | If enabled the component will have no default style. (you can still supply style through props) |
@ -124,7 +124,7 @@ If the decline button is enabled then the (onDecline) prop function can be used,
| flipButtons | boolean | false | If enabled the accept and decline buttons will be flipped |
| ButtonComponent | React component | button | React Component to render as a button. |
| sameSite | string, "strict", "lax" or "none" | none | Cookies sameSite attribute value |
| cookieSecurity | boolean | location ? location.protocol === "https:" : true | Cookie security level. Defaults to true unless running on http. |
| cookieSecurity | boolean | undefined | Cookie security level. Defaults to true unless running on http. |
## Debugging it

View File

@ -729,10 +729,14 @@ var CookieConsent = function (_Component) {
var _props3 = this.props,
extraCookieOptions = _props3.extraCookieOptions,
expires = _props3.expires,
sameSite = _props3.sameSite,
cookieSecurity = _props3.cookieSecurity;
sameSite = _props3.sameSite;
var cookieSecurity = this.props.cookieSecurity;
if (cookieSecurity === undefined) {
cookieSecurity = location ? location.protocol === "https:" : true;
}
var cookieOptions = _extends({ expires: expires }, extraCookieOptions, { sameSite: sameSite, secure: cookieSecurity });
// Fallback for older browsers where can not set SameSite=None, SEE: https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
@ -962,7 +966,6 @@ CookieConsent.defaultProps = {
enableDeclineButton: false,
flipButtons: false,
sameSite: SAME_SITE_OPTIONS.NONE,
cookieSecurity: location ? location.protocol === "https:" : true,
ButtonComponent: function ButtonComponent(_ref2) {
var children = _ref2.children,
props = _objectWithoutProperties(_ref2, ["children"]);

View File

@ -165,7 +165,12 @@ class CookieConsent extends Component {
* https://web.dev/samesite-cookie-recipes/#handling-incompatible-clients
*/
setCookie(cookieName, cookieValue) {
const { extraCookieOptions, expires, sameSite, cookieSecurity } = this.props;
const { extraCookieOptions, expires, sameSite } = this.props;
let { cookieSecurity } = this.props;
if (cookieSecurity === undefined) {
cookieSecurity = location ? location.protocol === "https:" : true;
}
let cookieOptions = { expires, ...extraCookieOptions, sameSite, secure: cookieSecurity };
@ -382,7 +387,6 @@ CookieConsent.defaultProps = {
enableDeclineButton: false,
flipButtons: false,
sameSite: SAME_SITE_OPTIONS.NONE,
cookieSecurity: location ? location.protocol === "https:" : true,
ButtonComponent: ({ children, ...props }) => <button {...props}>{children}</button>,
};