mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04: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
1 changed files with 4 additions and 3 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue