Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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 (
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')
}
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))
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;
}
private readonly handleClose = () => {
this.setState({notificationOpen: false})
const cookies = new ReactCookies()
cookies.set("rcl_consent_given", true)
}
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)
}
}
const AppWrapper = () => (
);
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) {