How to use the nookies.get function in nookies

To help you get started, we’ve selected a few nookies 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 feryandi / PilahPilihPilpres / fe / src / pages / result.js View on Github external
ResultPage.getInitialProps = async function(context) {
  const cookies = nookies.get(context);

  let payload = {
    fp: cookies['fp'],
    se: cookies['se'],
    to: cookies['to']
  }

  let host = "http://localhost:3000"
  if (process.env.NODE_ENV === 'production') {
    host = "https://pilahpilihpilpres.com"
  }

  // TODO: Only absolute URL
  let result = await fetch(host + `/api/result/get`, {
    method: 'POST',
    body: JSON.stringify(payload),
github feryandi / PilahPilihPilpres / fe / src / components / Question.js View on Github external
async sendAnswers(token) {
    const cookies = nookies.get();

    let payload = {
      fp: cookies['fp'],
      se: cookies['se'],
      to: cookies['to'],
      reCaptcha: token,
      answers: this.state.answers
    }

    let host = "http://localhost:3000"
    if (process.env.NODE_ENV === 'production') {
      host = "https://pilahpilihpilpres.com"
    }

    // TODO: Only absolute URL
    await fetch(host + `/api/answer/send`, {
github feryandi / PilahPilihPilpres / fe / src / pages / question.js View on Github external
Questionnaire.getInitialProps = async function(context) {
  const cookies = nookies.get(context);

  let payload = {
    fp: cookies['fp'],
    se: cookies['se'],
    to: cookies['to']
  }

  let host = "http://localhost:3000"
  if (process.env.NODE_ENV === 'production') {
    host = "https://pilahpilihpilpres.com"
  }

  // TODO: Only absolute URL
  let result = await fetch(host + `/api/question/get`, {
    method: 'POST',
    body: JSON.stringify(payload),
github feryandi / PilahPilihPilpres / fe / src / components / Home.js View on Github external
async getSession(fingerprint) {
    const cookies = nookies.get()

    let payload = {
      fp: fingerprint
    }
    
    if (!cookies.hasOwnProperty('se')) {
      let result = await fetch(`/api/session/generate`, {
        method: 'POST',
        body: JSON.stringify(payload),
        headers: {
            'Content-Type': 'application/json'
        }
      }).then(res => res.json());

      if (result['status'] === 'ok') {
        nookies.set({}, 'se', result['session'], {
github feryandi / PilahPilihPilpres / fe / src / components / Final.js View on Github external
deleteSession() {
    const cookies = nookies.get();
    nookies.destroy({}, 'se');
    nookies.destroy({}, 'to');
    Router.push('/');
  }
github SolidZORO / leaa / packages / leaa-www / src / utils / auth.util.ts View on Github external
const getAuthInfo = (ctx?: NextPageContext): Pick => {
  const defaultAuthInfo: IAuthInfo = {
    email: '',
    name: '',
  };

  let authInfo: string | undefined;

  if (isServer) {
    authInfo = nookies.get(ctx)[AUTH_INFO];
  }

  if (isClient) {
    authInfo = Cookies.get(AUTH_INFO);
  }

  try {
    return authInfo && JSON.parse(decodeURIComponent(authInfo));
  } catch (e) {
    return defaultAuthInfo;
  }
};
github feryandi / PilahPilihPilpres / fe / src / components / Home.js View on Github external
getUserIdentity() {
    const Fingerprint2 = require('fingerprintjs2');
    const options = {excludes: {userAgent: true}}

    const cookies = nookies.get()

    if (!cookies.hasOwnProperty('fp')) {
      Fingerprint2.get(options, (components) => {
          var values = components.map(function (component) { return component.value });
          var murmur = Fingerprint2.x64hash128(values.join(''), 31);
          nookies.set({}, 'fp', murmur, {
            maxAge: 30 * 24 * 60 * 60,
            path: '/',
          });
          this.getSession(murmur);
      });
    } else {
      this.getSession(cookies['fp']);
    }
  }

nookies

A set of cookie helpers for Next.js

MIT
Latest version published 3 years ago

Package Health Score

61 / 100
Full package analysis