mirror of
https://github.com/ether/etherpad-lite.git
synced 2026-05-08 05:36:09 +02:00
pad_cookie: Move initial cookie read+save to init()
Benefits of this change:
* It avoids race conditions with tests that clear cookies.
* Any attempt to get or set a value before `init()` is called will
throw an error, ensuring the API is used properly.
* Improved readability: It's easier to understand what the
`pad.noCookie` check is doing.
This commit is contained in:
parent
aeee5c0b69
commit
0df41a9a78
@ -21,15 +21,16 @@ const Cookies = require('./pad_utils').Cookies;
|
||||
exports.padcookie = new class {
|
||||
constructor() {
|
||||
this.cookieName_ = window.location.protocol === 'https:' ? 'prefs' : 'prefsHttp';
|
||||
}
|
||||
|
||||
init() {
|
||||
const prefs = this.readPrefs_() || {};
|
||||
delete prefs.userId;
|
||||
delete prefs.name;
|
||||
delete prefs.colorId;
|
||||
this.prefs_ = prefs;
|
||||
this.savePrefs_();
|
||||
}
|
||||
|
||||
init() {
|
||||
// Re-read the saved cookie to test if cookies are enabled.
|
||||
if (this.readPrefs_() == null) {
|
||||
$.gritter.add({
|
||||
title: 'Error',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user