• Stars
    star
    115
  • Rank 304,110 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 16 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cookies abstraction for Ember.js that works both in the browser as well as with Fastboot on the server

CI

ember-cookies

ember-cookies implements an abstract cookie API that works both in the browser (via document.cookie) as well as with Fastboot in the server context (using the request and response accessible via the fastBoot service).

Having access to cookies both in the browser as well as in FastBoot is key to being able to share a common session.

Installation

Install ember-cookies with

ember install ember-cookies

Example Usage

// app/controllers/application.js
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
const { keys } = Object;

export default class ApplicationController extends Controller {
  @service cookies;

  @computed
  get allCookies () {
    let cookieService = this.cookies;
    cookieService.write('now', new Date().getTime());

    let cookies = cookieService.read();
    return keys(cookies).reduce((acc, key) => {
      let value = cookies[key];
      acc.push({ name: key, value });

      return acc;
    }, []);
  }
}

API

The cookies service has methods for reading and writing cookies:

  • read(name, options = {}): reads the cookie with the given name, returns its value as a String; options can be used to set raw (boolean, disables URL-decoding the value).
  • write(name, value, options = {}): writes a cookie with the given name and value; options can be used to set domain, expires (Date), maxAge (time in seconds), path, secure, raw (boolean, disables URL-encoding the value) and sameSite.
  • clear(name, options = {}): clears the cookie so that future reads do not return a value; options can be used to specify domain, path or secure.
  • exists(name): checks whether a cookie exists at all (even with a falsy value) and returns true if that is the case or false otherwise.

Testing

ember-cookies exposes the clearAllCookies test helper that clears all known cookies to reset state before and/or after tests:

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { clearAllCookies } from 'ember-cookies/test-support';

module('Unit | Some Module', function (hooks) {
  setupTest(hooks);

  hooks.beforeEach(function () {
    clearAllCookies();
  });

  // or you may wat to clear cookies after the test run
  hooks.afterEach(function () {
    clearAllCookies();
  });
});

License

ember-cookies is developed by and Β© Mainmatter GmbH and contributors. It is released under the MIT License.

ember-cookies is not an official part of Ember.js and is not maintained by the Ember.js Core Team.

More Repositories

1

100-exercises-to-learn-rust

A self-paced course to learn Rust, one exercise at a time.
Rust
3,527
star
2

ember-simple-auth

A library for implementing authentication/authorization in Ember.js applications.
JavaScript
1,926
star
3

ember-test-selectors

Enabling better element selectors in Ember.js tests
JavaScript
262
star
4

rust-telemetry-workshop

Build a comprehensive toolkit to detect, troubleshoot and resolve issues with Rust applications.
Rust
224
star
5

qunit-dom

High Level DOM Assertions for QUnit
TypeScript
178
star
6

excellent

Source Code analysis gem for Ruby and Rails
Ruby
156
star
7

rails_api_auth

Lightweight Rails Engine that implements the "Resource Owner Password Credentials Grant" OAuth 2.0 flow as well as Facebook authentication
Ruby
139
star
8

highlight

Syntax Higlighting plugin for Ruby on Rails
Ruby
131
star
9

cargo-autoinherit

(Auto)DRY for your Rust dependencies
Rust
124
star
10

rust-advanced-testing-workshop

A course to move beyond the built-in Rust testing toolkit.
Rust
95
star
11

ast-workshop

"Abstract Syntax Forestry" workshop for EmberConf 2020
JavaScript
86
star
12

breethe-client

Air Quality Data for Locations around the World
JavaScript
75
star
13

ember-cli-simple-auth

Ember CLI Adon for the Ember Simple Auth library
JavaScript
54
star
14

ember-intl-analyzer

Find missing or unused translations in your Ember.js projects
JavaScript
48
star
15

ember-hbs-minifier

Stripping whitespace out of your Handlebars templates
JavaScript
48
star
16

ember-validated-form-buffer

A validated form buffer that wraps Ember Data models for use in forms.
JavaScript
47
star
17

continue-on-error-comment

GitHub action to add comment when a continue-on-error job fails
JavaScript
41
star
18

breethe-server

Air Quality Data for Locations around the World
Elixir
40
star
19

rust-python-interoperability

A self-paced course to write Python extensions in Rust, one exercise at a time.
Rust
32
star
20

ember-promise-modals

The easy solution for rendering and handling modals in Ember.js apps. Promised.
JavaScript
31
star
21

ember-simple-auth-example

Example project showing how to use Ember Simple Auth with Ember CLI
JavaScript
30
star
22

svelte-promise-modals

Modals in Svelte made easy. Promised.🀞
Svelte
26
star
23

qunit-console-grouper

QUnit plugin that groups console messages by test
JavaScript
22
star
24

ember-cli-simple-auth-devise

Ember CLI Addon for the Ember Simple Auth Devise package
JavaScript
22
star
25

ember-asset-size-action

Comment with the diff for the asset sizes on Pull Request
JavaScript
22
star
26

ember-cli-simple-auth-oauth2

Ember CLI Addon for the Ember Simple Auth OAuth 2.0 package
JavaScript
20
star
27

ember-cli-deploy-webhooks

Ember CLI Deploy plugin for calling webhooks during deployments
JavaScript
19
star
28

rust-workshop-runner

A CLI tool to drive test-driven Rust workshops
Rust
17
star
29

ember-classy-computed

An Ember addon for Class based Computed Properties
JavaScript
16
star
30

mainmatter.com

The source code for https://mainmatter.com
Nunjucks
16
star
31

qunit-dom-codemod

Basic codemod to automatically convert your assertions to qunit-dom assertions
JavaScript
14
star
32

eslint-plugin-ember-concurrency

ESLint plugin for ember-concurrency users
JavaScript
13
star
33

playbook

A book describing the patterns and practices that Mainmatter uses to build lasting products, systematically.
HTML
13
star
34

ember-workshop

The example apps for simplabs' Ember.js Workshop
12
star
35

ember-cli-pixijs

An Ember CLI Addon that wraps pixi.js
JavaScript
12
star
36

emblem-migrator

Migrate Emblem.js to pretty Handlebars files
JavaScript
9
star
37

ember-cli-simple-auth-testing

Ember CLI Addon for the Ember Simple Auth Testing package
JavaScript
9
star
38

ember-cli-simple-auth-cookie-store

Ember CLI Addon for the Ember Simple Auth Cookie Store package
JavaScript
8
star
39

testem-gitlab-reporter

GitLab/JUnit reporter for testem
JavaScript
8
star
40

rails_api_auth-demo

Demo project using the rails_api_auth engine
Ruby
7
star
41

ember-auto-computed

JavaScript
7
star
42

ember-cli-simple-auth-torii

Ember CLI Addon for the Ember Simple Auth Torii package
JavaScript
7
star
43

ember-template-lint-plugin-css-modules

ember-template-lint plugin for ember-css-modules
JavaScript
7
star
44

ember-api-actions

Ember.js addon allowing you to easily implement non-CRUD actions for your Ember Data models
JavaScript
6
star
45

ember-error-route

JavaScript
6
star
46

mainmatter-website-mailer

Mailer for the contact form on mainmatter.com – Cloudflare worker written in Rust
Rust
5
star
47

ember-hotspots

Create interactive prototypes from scratch and design mockups using little code but the full power of the Ember.js ecosystem.
JavaScript
5
star
48

ember-scroll

A sensible default implementation of scrolling for Ember apps, aiming to mimic static site behaviour.
JavaScript
4
star
49

asset-size-reporter

Generic asset size comparison and reporting tool
JavaScript
4
star
50

mocha-diff

Mocha's diff algorithm extracted for anyone to use πŸŽ‰
JavaScript
4
star
51

ember-simple-auth-component

Bower repository for Ember Simple Auth
JavaScript
4
star
52

svelte-workshop-music-player

JavaScript
4
star
53

sheepdog

Sheepdog...herd you async task!
TypeScript
3
star
54

eslint-plugin-qunit-dom

An ESLint plugin for qunit-dom that automatically fixes the most common issues.
JavaScript
2
star
55

compare-fixture

JavaScript
1
star
56

ember-cli-list-addons

JavaScript
1
star
57

git-workshop

1
star
58

eslint-config-simplabs

ESLint config for all simplabs projects
JavaScript
1
star
59

auto-reveal

JavaScript
1
star
60

auto-reveal-theme-mainmatter

CSS
1
star
61

sveltekit-super-rentals

JavaScript
1
star
62

who-ran-me

Small utillity to check if script was run with npm or yarn
JavaScript
1
star