Rename useSessionStorage to clientStorage for more flexibility

This commit is contained in:
Jan Dvorak
2024-03-28 20:16:50 +01:00
parent 8531599a61
commit aa5c565c4d
3 changed files with 5 additions and 4 deletions

View File

@@ -75,6 +75,7 @@ export namespace Accounts {
collection?: string | undefined;
loginTokenExpirationHours?: number | undefined;
tokenSequenceLength?: number | undefined;
clientStorage?: 'session' | 'local';
}): void;
function onLogin(

View File

@@ -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();

View File

@@ -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'))