Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secure: true for production #467

Open
github-actions bot opened this issue Apr 20, 2023 · 0 comments
Open

secure: true for production #467

github-actions bot opened this issue Apr 20, 2023 · 0 comments
Labels

Comments

@github-actions
Copy link

secure: true for production

{ expires: 1, secure: false } // TODO secure: true for production

import { Cookies } from 'quasar';

import Env from 'src/env';

/**
 * This file contains all cookie-related helper functions
 */

/**
 * Persists a given payload to one or multiple cookies
 *
 * @param category - sub-category to store the cookie to
 * @param payload - the data to persist (in stringified form)
 */
export function persistToCookies(
  category: string,
  payload: Record<string, any>
): void {
  // Set cookie when SSR fetch is done (i.e. only browser can set a cookie)
  if (!Env.SERVER) {
    // Set 'secure' to true for production
    Object.keys(payload).forEach((key: string) => {
      Cookies.set(
        `${category}.${key}`,
        JSON.stringify(payload[key]),
        { expires: 1, secure: false } // TODO secure: true for production
      );
    });
  }
}

/**
 * Deletes all cookies within a given category
 *
 * @param category - the category within which to delete (e.g. "authentication")
 */
export function deleteCookies(category: string): void {
  const allCookies: Set<unknown> = Cookies.getAll() as Set<unknown>;

  Object.keys(allCookies).forEach((cookieKey: string) => {
    if (cookieKey.startsWith(`${category}.`)) {
      Cookies.remove(cookieKey);
    }
  });
}

310cadf0b224d2701bbe4236652d23596f8b01c0

@github-actions github-actions bot added the todo label Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants