mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Rename useSessionStorage to clientStorage for more flexibility
This commit is contained in:
1
packages/accounts-base/accounts-base.d.ts
vendored
1
packages/accounts-base/accounts-base.d.ts
vendored
@@ -75,6 +75,7 @@ export namespace Accounts {
|
||||
collection?: string | undefined;
|
||||
loginTokenExpirationHours?: number | undefined;
|
||||
tokenSequenceLength?: number | undefined;
|
||||
clientStorage?: 'session' | 'local';
|
||||
}): void;
|
||||
|
||||
function onLogin(
|
||||
|
||||
@@ -9,7 +9,7 @@ import {AccountsCommon} from "./accounts_common.js";
|
||||
* @param {Object} options an object with fields:
|
||||
* @param {Object} options.connection Optional DDP connection to reuse.
|
||||
* @param {String} options.ddpUrl Optional URL for creating a new DDP connection.
|
||||
* @param {Boolean} options.useSessionStorage Optional Use session storage to store tokens and related data. Defaults to false, which means that local storage is used.
|
||||
* @param {'session' | 'local'} options.clientStorage Optional Define what kind of storage you want for credentials on the client. Default is 'local' to use `localStorage`. Set to 'session' to use session storage.
|
||||
*/
|
||||
export class AccountsClient extends AccountsCommon {
|
||||
constructor(options) {
|
||||
@@ -28,7 +28,7 @@ export class AccountsClient extends AccountsCommon {
|
||||
this._initUrlMatching();
|
||||
|
||||
// Determine whether to use local or session storage to storage credentials and anything else.
|
||||
this.storageLocation = (options?.useSessionStorage || Meteor.settings?.public?.packages?.accounts?.useSessionStorage) ? window.sessionStorage : Meteor._localStorage;
|
||||
this.storageLocation = (options?.clientStorage === 'session' || Meteor.settings?.public?.packages?.accounts?.clientStorage === 'session') ? window.sessionStorage : Meteor._localStorage;
|
||||
|
||||
// Defined in localstorage_token.js.
|
||||
this._initLocalStorage();
|
||||
|
||||
@@ -306,7 +306,7 @@ Tinytest.addAsync(
|
||||
|
||||
testAsyncMulti('accounts - storage', [
|
||||
function (test, expect) {
|
||||
Accounts.config({ useSessionStorage: true })
|
||||
Accounts.config({ clientStorage: 'session' })
|
||||
test.isTrue(Accounts._options.useSessionStorage)
|
||||
test.isNotUndefined(sessionStorage.getItem('Meteor.loginToken'))
|
||||
test.isUndefined(localStorage.getItem('Meteor.loginToken'))
|
||||
@@ -314,7 +314,7 @@ testAsyncMulti('accounts - storage', [
|
||||
removeTestUser()
|
||||
},
|
||||
function (test, expect) {
|
||||
Accounts.config({ useSessionStorage: false })
|
||||
Accounts.config({ clientStorage: 'local' })
|
||||
test.isFalse(Accounts._options.useSessionStorage)
|
||||
test.isUndefined(sessionStorage.getItem('Meteor.loginToken'))
|
||||
test.isNotUndefined(localStorage.getItem('Meteor.loginToken'))
|
||||
|
||||
Reference in New Issue
Block a user