How to use nookies - 10 common examples

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 codeleakteam / codeleak / nextjs / helpers / functions / auth.js View on Github external
export const auth = ctx => {
  const { codeleakAuthToken, codeleakUser } = parseCookies(ctx)
  const isLoggedIn = !!codeleakAuthToken && !!codeleakUser
  // console.log('[auth] isLoggedIn ', isLoggedIn)
  // console.log('[auth] codeleakUser', codeleakUser)
  // console.log('[auth] codeleakAuthToken', codeleakAuthToken)

  // Protected routes are the ones we show only to users that are logged in
  let isProtectedRoute
  let isGuestRoute

  // SSR
  if (ctx.req) {
    isProtectedRoute = protectedRoutes.filter(r => r === ctx.req.url)[0] ? true : false
    isGuestRoute = guestRoutes.filter(r => r === ctx.req.url)[0] ? true : false

    if (isProtectedRoute && !isLoggedIn) {
      ctx.res.writeHead(302, { location: '/sign_in' })
github codeleakteam / codeleak / nextjs / helpers / functions / auth.js View on Github external
export const logout = () => {
  destroyCookie(undefined, 'codeleakUser')
  destroyCookie(undefined, 'codeleakAuthToken')

  // window.localStorage.setItem("logout", Date.now()guardialo on successguardialo on success);

  console.log('Logged out. Redirecting')
  Router.push('/')
  message.success('Successfully logged out!')
}
github codeleakteam / codeleak / nextjs / helpers / functions / auth.js View on Github external
export const logout = () => {
  destroyCookie(undefined, 'codeleakUser')
  destroyCookie(undefined, 'codeleakAuthToken')

  // window.localStorage.setItem("logout", Date.now()guardialo on successguardialo on success);

  console.log('Logged out. Redirecting')
  Router.push('/')
  message.success('Successfully logged out!')
}
github codeleakteam / codeleak / nextjs / helpers / functions / auth.js View on Github external
export const login = async ({ user, token }) => {
  try {
    const userJSON = JSON.stringify(user)
    setCookie(undefined, 'codeleakUser', userJSON)
    setCookie(undefined, 'codeleakAuthToken', token)
    Router.push('/')
  } catch (err) {
    // Ignorguardialo on successguardialo on successe
    console.error('[login]', err)
  }
}
github codeleakteam / codeleak / nextjs / helpers / functions / auth.js View on Github external
export const login = async ({ user, token }) => {
  try {
    const userJSON = JSON.stringify(user)
    setCookie(undefined, 'codeleakUser', userJSON)
    setCookie(undefined, 'codeleakAuthToken', token)
    Router.push('/')
  } catch (err) {
    // Ignorguardialo on successguardialo on successe
    console.error('[login]', err)
  }
}
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 dpla / dpla-frontend / pages / search / index.js View on Github external
Search.getInitialProps = async context => {
  const query = context.query;
  const req = context.req;
  const isLocal = SITE_ENV === "local";
  const isQA = parseCookies(context).hasOwnProperty("qa");
  const currentUrl = getCurrentUrl(req);
  const q = query.q
    ? encodeURIComponent(query.q).replace(/'/g, "%27").replace(/"/g, "%22")
    : "";

  let hasDates = false;
  const theseFacets = isQA ? qaFacets : possibleFacets;

  const queryArray = theseFacets
    .map(facet => {
      if (facet.indexOf("sourceResource.date") !== -1 && !hasDates) {
        hasDates = true; // do it only once for date queries
        // the date “facets” from ES do not map to the way the API expects requests
        // remove whatever is after the last periot (“begin” or “end”)
        facet = facet.replace(".begin", "");
        facet = facet.replace(".end", "");
github ShadOoW / web-starter-kit / pages / _app.js View on Github external
static async getInitialProps({ Component, ctx }) {
    let pageProps = {};

    // On server-side, this runs once and creates new services
    // On client-side, this always reuses existing services

    const cookies = parseCookies(ctx);

    const mobxServices = getServices({
      language: cookies['next-i18next'] || i18n.language,
    });

    // Make services available to page's `getInitialProps`
    ctx.mobxServices = mobxServices;

    // Call "super" to run page's `getInitialProps`
    if (Component.getInitialProps) {
      pageProps = await Component.getInitialProps(ctx);
    }

    // Gather serialization-friendly data from services
    const initialData = {
      language: mobxServices.languageService.data(),

nookies

A set of cookie helpers for Next.js

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis