import { type Timer } from '@ember/runloop'; import BaseStore from './base'; import type CookiesService from 'ember-cookies/services/cookies'; /** 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 {@linkplain 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: ```js // app/controllers/login.js import Controller from '@ember/controller'; import { 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:__ ```js // app/session-stores/application.js import CookieStore from 'ember-simple-auth/session-stores/cookie'; export default class ApplicationSessionStore extends CookieStore {} ``` @class CookieStore @extends BaseStore @public */ export default class CookieStore extends BaseStore { _syncDataTimeout: Timer | null; _renewExpirationTimeout: Timer | null; /** 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. @memberof CookieStore @property cookieDomain @type String @default null @public */ _cookieDomain: null; cookieDomain: null | string; /** 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" @memberof CookieStore @property sameSite @type String @default null @public */ _sameSite: null; sameSite: null | 'Strict' | 'Lax' | 'None'; /** The name of the cookie. @memberof CookieStore @property cookieName @type String @default ember_simple_auth-session @public */ _cookieName: string; _oldCookieName: string | null; cookieName: string; /** The path to use for the cookie, e.g., "/", "/something". @memberof CookieStore @property cookiePath @type String @default '/' @public */ _cookiePath: string; cookiePath: string; /** 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). @memberof CookieStore @property cookieExpirationTime @default null @type Integer @public */ _cookieExpirationTime: null; cookieExpirationTime: number | null; /** Allows servers to assert that a cookie should opt in to partitioned storage, i.e. use a separate cookie per top level site if the cookie is used in a third party context Available options: - null - true @memberof CookieStore @property partitioned @type Boolean @default null @public */ _partitioned: null; partitioned: null | boolean; _cookies: CookiesService; _fastboot: any; _secureCookies(): boolean; _isPageVisible(): boolean; _isFastBoot: boolean; _lastData: Record | null; init(properties: any): void; /** Persists the `data` in the cookie. @memberof CookieStore @method persist @param {Object} data The data to persist @return {Promise} A promise that resolves when the data has successfully been persisted and rejects otherwise. @public */ persist(data: Record): Promise; /** Returns all data currently stored in the cookie as a plain object. @memberof CookieStore @method restore @return {Promise} A promise that resolves with the data currently persisted in the store when the data has been restored successfully and rejects otherwise. @public */ restore(): Promise; /** Clears the store by deleting the cookie. @memberof CookieStore @method clear @return {Promise} A promise that resolves when the store has been cleared successfully and rejects otherwise. @public */ clear(): Promise; _read(name: string): string; _calculateExpirationTime(): number | undefined; _write(value: string, expiration: number | undefined): void; _syncData(): Promise; _renew(): Promise; _renewExpiration(): Promise; rewriteCookie(): void; setRedirectTarget(url: string): void; getRedirectTarget(): string | null; clearRedirectTarget(): void; }