Skip to content

Commit

Permalink
Lazily access transaction
Browse files Browse the repository at this point in the history
This is done to not throw in the Auth0Client constructor when cookies and site data are disabled.
  • Loading branch information
frederikprijck committed Jun 14, 2023
1 parent 7ca5d97 commit ee72e15
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/transaction-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,28 @@ interface Transaction {
}

export class TransactionManager {
private transaction: Transaction | undefined;
private storageKey: string;

constructor(private storage: ClientStorage, private clientId: string, private cookieDomain?: string) {
constructor(
private storage: ClientStorage,
private clientId: string,
private cookieDomain?: string
) {
this.storageKey = `${TRANSACTION_STORAGE_KEY_PREFIX}.${this.clientId}`;
this.transaction = this.storage.get(this.storageKey);
}

public create(transaction: Transaction) {
this.transaction = transaction;

this.storage.save(this.storageKey, transaction, {
daysUntilExpire: 1,
cookieDomain: this.cookieDomain,
cookieDomain: this.cookieDomain
});
}

public get(): Transaction | undefined {
return this.transaction;
return this.storage.get(this.storageKey);
}

public remove() {
delete this.transaction;
this.storage.remove(this.storageKey, {
cookieDomain: this.cookieDomain
});
Expand Down

0 comments on commit ee72e15

Please sign in to comment.