How to use the react-cookie.Cookies function in react-cookie

To help you get started, we’ve selected a few react-cookie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zprima / jwt-cors-app / app / pages / index.js View on Github external
import React from 'react';
import Link from 'next/link.js';
import axios from 'axios';
import { Cookies } from 'react-cookie';

const serverUrl = 'http://localhost:3001';

// set up cookies
const cookies = new Cookies();
class Index extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      token: cookies.get('token') || null
    }
  }

  onLoginClick = async () => {
    console.log("Login called");
    const response = await axios.get(serverUrl + '/api/login')
    const token = response.data.token;
    cookies.set('token', token);
    this.setState({
      token: token
github zprima / jwt-cors-app / app / pages / secret.js View on Github external
import React from 'react';
import axios from 'axios';
import { Cookies } from 'react-cookie';
import { handleAuthSSR } from '../utils/auth';

const serverUrl = 'http://localhost:3001';

// set up cookies
const cookies = new Cookies();

class Secret extends React.Component {

  onPingCall = async (e) => {
    const token = cookies.get('token')

    try {
      const res = await axios.get(serverUrl + '/api/ping', { headers: { 'Authorization': token } });
      console.log(res.data.msg);
    } catch (err) {
      console.log(err.response.data.msg);
    }
  }

  render() {
    return (
github zprima / jwt-cors-app / app / utils / auth.js View on Github external
import axios from 'axios';
import Router from 'next/router';
import { Cookies } from 'react-cookie';
// set up cookies
const cookies = new Cookies();
const serverUrl = 'http://localhost:3001';

export async function handleAuthSSR(ctx) {
  let token = null;

  // if context has request info aka Server Side
  if (ctx.req) {
    // ugly way to get cookie value from a string of values
    // good enough for demostration
    token = ctx.req.headers.cookie.replace(/(?:(?:^|.*;\s*)token\s*\=\s*([^;]*).*$)|^.*$/, "$1");
  }
  else {
    // we dont have request info aka Client Side
    token = cookies.get('token')
  }
github DAO-IPCI / DAO-IPCI / dapp / src / modules / app / actions.js View on Github external
import Notifications from 'react-notification-system-redux';
import i18next from 'i18next'
import _ from 'lodash'
import { Cookies } from 'react-cookie'
import { SET_DAO_ADDRESS, SET_ROLE, SET_LANGUAGE } from './actionTypes'
import { add } from '../log/actions'

const cookies = new Cookies();

export function flashMessage(message, type = 'info') {
  return (dispatch) => {
    const notificationOpts = {
      // title: 'Hey, it\'s good to see you!',
      message,
      position: 'tr',
      autoDismiss: 10
    };
    if (type === 'error') {
      dispatch(Notifications.error(notificationOpts))
    } else {
      dispatch(Notifications.info(notificationOpts))
    }
    if (!_.isEmpty(message)) {
      dispatch(add(message))
github alleyinteractive / irving / packages / core / services / fetchComponents.js View on Github external
function getQueryParamsFromCookies(cookieData) {
  const cookieAllowList = env.COOKIE_MAP_LIST ?
    env.COOKIE_MAP_LIST.split(',') :
    [];

  const cookies = new Cookies(cookieData);
  const cookieObject = cookies.getAll({ doNotParse: true });
  const cookieQueryParams = pick(cookieAllowList)(cookieObject);

  return cookieQueryParams;
}
github SaltieRL / DistributedReplays / webapp / src / AppListener.tsx View on Github external
private readonly handleClose = () => {
        this.setState({notificationOpen: false})
        const cookies = new ReactCookies()
        cookies.set("rcl_consent_given", true)
    }
github DAO-IPCI / DAO-IPCI / dapp / src / shared / containers / app.js View on Github external
componentWillMount() {
    this.props.updateBalance()
    const cookies = new Cookies();
    let address = cookies.get('dao_address')
    if (!address) {
      address = PROGRAMMS[0].address;
    }
    this.props.setDaoAddress(address)
    if (!this.props.isCoreLoad) {
      this.props.loadCore(address);
    }
    const language = cookies.get('language')
    if (language) {
      this.props.setLanguage(language)
    }
  }
github buildo / react-cookie-banner / src / CookieBanner.tsx View on Github external
PropTypes.number,
      PropTypes.shape({
        years: PropTypes.number,
        days: PropTypes.number,
        hours: PropTypes.number
      })
    ]),
    cookiePath: PropTypes.string,
    dismissOnScroll: PropTypes.bool,
    dismissOnScrollThreshold: PropTypes.number
  }

  static defaultProps = {
    onAccept: () => {},
    dismissOnScroll: true,
    cookies: new Cookies(),
    cookie: 'accepts-cookies',
    cookieExpiration: { years: 1 },
    buttonMessage: 'Got it',
    dismissOnScrollThreshold: 0,
    styles: {}
  };

  state = { listeningScroll: false }

  componentDidMount() {
    this.addOnScrollListener();
  }

  addOnScrollListener = (props?: CookieBanner.Props) => {
    const _props = props || this.props;
    if (!this.state.listeningScroll && !this.hasAcceptedCookies() && _props.dismissOnScroll) {