How to use universal-cookie - 10 common examples

To help you get started, we’ve selected a few universal-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 Excel-MEC / ExcelPlay-2019 / src / config / auth0-samp.js View on Github external
constructor() {
    const csrftoken = cookieService.get('csrftoken');
    if (!csrftoken) {
      const loader = new ProgressiveLoader();
      loader.placeLoader('Auth_const');
      this.http
        .get(ApiRoot() + '/auth/v1/token', {
          withCredentials: true,
          observe: 'response',
        })
        .subscribe(res => {
          console.log(res);
          loader.removeLoader();
          // window.location.reload(true);
        });
    }
  }
github Excel-MEC / ExcelPlay-2019 / src / config / auth0-samp.js View on Github external
setSession = authResult => {
    // Set the time that the access token will expire at
    const expiresAt = JSON.stringify(
      authResult.expiresIn * 1000 + new Date().getTime(),
    );
    localStorage.setItem('access_token', authResult.accessToken);
    localStorage.setItem('id_token', authResult.idToken);
    localStorage.setItem('expires_at', expiresAt);
    const body = new FormData();
    const csrftoken = cookieService.get('csrftoken');
    // if (csrftoken) {
    body.append('access_token', authResult.accessToken);
    body.append('csrfmiddlewaretoken', csrftoken);
    // const loader = new ProgressiveLoader();
    // loader.placeLoader('Auth_ss');
    // return this.http
    //   .post(ApiRoot() + '/auth/v1/signin', body, { withCredentials: true })
    //   .pipe(
    //     map(res => {
    //       loader.removeLoader();
    //       // console.log(res.json());
    //       return res;
    //     }),
    //   );
    // }
  };
github rnaga / wordpress-rest-admin / src / services / auth.js View on Github external
import Cookies from 'universal-cookie';
import newHttpError from '../util/newHttpError';
import caches from '../util/caches';

// Use cookie to store JWT's login token
const cookies = new Cookies();

const auth = {

    authorize: async () => {

        const login_token = cookies.get('login_token');

        if(!login_token)
            throw new Error('Login_Token_Not_Defined');

        return {
            httpOptions: {
                headers: {Authorization: `Bearer ${login_token}`}
            }
        };
    },
github matthewmueller / next-cookies / index.js View on Github external
var Cookies = require("universal-cookie");
// we seem to sometimes get the ES6 version despite requesting cjs here, not sure why
// this isn't the ideal fix, but it'll do for now
Cookies = Cookies.default || Cookies;

function nextCookies(ctx, options) {
  // Note: Next.js Static export sets ctx.req to a fake request with no headers
  var header = ctx.req && ctx.req.headers && ctx.req.headers.cookie;
  var uc = new Cookies(header);
  return uc.getAll(options);
}

module.exports = nextCookies;
github aarkerio / schnellentest / lib / assets / frontend / javascripts / actions / questions.js View on Github external
require('es6-promise').polyfill()
require('isomorphic-fetch')

import Cookies from 'universal-cookie'

export const RECEIVE_QUESTION    = 'RECEIVE_QUESTION'
export const REQUEST_QUESTION    = 'REQUEST_QUESTION'

const cookies = new Cookies();

function headers(set_cookie=false) {
  let headers = {
        'Accept':       'application/json',
        'Content-Type': 'application/json',
        'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
      }
  if (set_cookie){
    headers['Authorization'] = "Bearer " + cookies.get('remember_user_token')
  }
  return headers;
}

function requestTest(test_id) {
  return {
    type: REQUEST_POSTS,
github evgeny-nadymov / telegram-react / src / Stores / PlayerStore.js View on Github external
break;
            }
            case 'clientUpdateMediaShuffle': {
                const { shuffle } = update;

                this.shuffle = shuffle;

                this.emit(update['@type'], update);
                break;
            }
            case 'clientUpdateMediaPlaybackRate': {
                const { playbackRate } = update;

                this.playbackRate = playbackRate;

                const cookies = new Cookies();
                cookies.set('playbackRate', playbackRate);

                this.emit(update['@type'], update);
                break;
            }
            case 'clientUpdateMediaPlay': {
                this.playing = true;

                this.emit(update['@type'], update);
                break;
            }
            case 'clientUpdateMediaTitleMouseOver': {
                this.emit(update['@type'], update);
                break;
            }
            case 'clientUpdateMediaPause': {
github jackhutu / jackblog-react / src / server.js View on Github external
export default function render(req, res) {
  const cookies = new Cookies(req.headers.cookie)
  const history = createMemoryHistory()
  const token = cookies.get('token') || null
  const styleMode = cookies.get('styleMode') || 'day-mode'
  const store = configureStore({
    auth:fromJS({
      token: token,
      user: null
    }),
    globalVal:fromJS({
      styleMode: styleMode,
      captchaUrl: API_ROOT + 'users/getCaptcha?'
    })
  }, history)
  const batch = matchRoutes(routes, req.url)
  return fetchAllData(batch, store.dispatch, token).then(function(data){
    const context = {}
github daixianceng / react-universal-example / src / server.js View on Github external
app.use((req, res, next) => {
  req.cookies = new Cookies(req.headers.cookie);
  next();
});
app.use(bodyParser.urlencoded({ extended: true }));
github fossasia / susi_skill_cms / src / redux / reducers / app.js View on Github external
import { handleActions } from 'redux-actions';
import actionTypes from '../actionTypes';

import Cookies from 'universal-cookie';

const cookies = new Cookies();

const defaultState = {
  userName: '',
  email: '',
  uuid: '',
  accessToken: '',
  isAdmin: false,
  apiKeys: {},
  userSkills: [],
};

const { emailId, uuid, loggedIn, username } = cookies.getAll();

const cookiesAppValues = {
  email: emailId,
  uuid,
github reactivestack / cookies / packages / universal-cookie-koa / src / index.js View on Github external
return function(ctx, next) {
    ctx.request.universalCookies = new Cookies(
      ctx.request.headers.cookie || '',
      {
        onSet(name, value, options) {
          ctx.cookies.set(name, value, options);
        },
        onRemove(name) {
          ctx.cookies.set(name, null);
        }
      }
    );
    return next();
  };
}

universal-cookie

Universal cookies for JavaScript

MIT
Latest version published 24 days ago

Package Health Score

85 / 100
Full package analysis