Class

CookieStore

CookieStore()

Constructor

# new CookieStore()

Session store that persists data in a cookie.

By default the cookie session store uses a session cookie that expires and is deleted when the browser is closed. The cookie expiration period can be configured by setting the CookieStore.cookieExpirationTime property. This can be used to implement "remember me" functionality that will either store the session persistently or in a session cookie depending on whether the user opted in or not:

// app/controllers/login.js
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default class LoginController extends Controller {
  @service session;
  _rememberMe = false;

  get rememberMe() {
    return this._rememberMe;
  }

  set rememberMe(value) {
    let expirationTime = value ? (14 * 24 * 60 * 60) : null;
    this.set('session.store.cookieExpirationTime', expirationTime);
    this._rememberMe = value;
  }
}

Applications that use FastBoot must use this session store by defining the application session store like this:

// app/session-stores/application.js
import CookieStore from 'ember-simple-auth/session-stores/cookie';

export default class ApplicationSessionStore extends CookieStore {}

View Source session-stores/cookie.js, line 27

Extends

Members

String

# static _cookieDomain

The domain to use for the cookie, e.g., "example.com", ".example.com" (which includes all subdomains) or "subdomain.example.com". If not explicitly set, the cookie domain defaults to the domain the session was authenticated on.

Properties:
Name Type Description
cookieDomain
Default Value:
  • null

View Source session-stores/cookie.js, line 89

Integer

# static _cookieExpirationTime

The expiration time for the cookie in seconds. A value of null will make the cookie a session cookie that expires and gets deleted when the browser is closed.

The recommended minimum value is 90 seconds. If your value is less than
that, the cookie may expire before its expiration time is extended
(expiration time is extended every 60 seconds).
Properties:
Name Type Description
cookieExpirationTime
Default Value:
  • null

View Source session-stores/cookie.js, line 148

String

# static _cookieName

The name of the cookie.

Properties:
Name Type Description
cookieName
Default Value:
  • ember_simple_auth-session

View Source session-stores/cookie.js, line 116

String

# static _cookiePath

The path to use for the cookie, e.g., "/", "/something".

Properties:
Name Type Description
cookiePath
Default Value:
  • '/'

View Source session-stores/cookie.js, line 130

String

# static _sameSite

Allows servers to assert that a cookie ought not to be sent along with cross-site requests, which provides some protection against cross-site request forgery attacks (CSRF). Available options: - "Strict" - "Lax"

Properties:
Name Type Description
sameSite
Default Value:
  • null

View Source session-stores/cookie.js, line 104

Methods

# static clear() → {RSVP.Promise}

Clears the store by deleting the cookie.

View Source session-stores/cookie.js, line 244

A promise that resolves when the store has been cleared successfully and rejects otherwise.

RSVP.Promise

# static persist(data) → {RSVP.Promise}

Persists the data in the cookie.

Parameters:
Name Type Description
data Object

The data to persist

View Source session-stores/cookie.js, line 210

A promise that resolves when the data has successfully been persisted and rejects otherwise.

RSVP.Promise

# static restore() → {RSVP.Promise}

Returns all data currently stored in the cookie as a plain object.

View Source session-stores/cookie.js, line 227

A promise that resolves with the data currently persisted in the store when the data has been restored successfully and rejects otherwise.

RSVP.Promise