Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Recursive call calling out of stack #102

Open
sremiger1 opened this issue Aug 21, 2018 · 1 comment
Open

Recursive call calling out of stack #102

sremiger1 opened this issue Aug 21, 2018 · 1 comment

Comments

@sremiger1
Copy link

sremiger1 commented Aug 21, 2018

TokenStorage.prototype.get = function (provider) {
        var token = _super.prototype.get.call(this, provider);
        if (token == null) {
            return token;
        }
        var expired = TokenStorage.hasExpired(token);
        if (expired) {
            _super.prototype.delete.call(this, provider);
            return null;
        } else {
            return token;
        }
    };

_super.prototype.delete.call(this, provider); is being called if expired. Which in turn is calling get causing a circular reference and blowing the stack.

Storage.prototype.delete = function (key) {
        try {
            var value = this.get(key);
            if (value === undefined) {
                throw new ReferenceError("Key: " + key + " not found.");
            }
            var scopedKey = this._scope(key);
            this._storage.removeItem(scopedKey);
            return value;
        } catch (error) {
            throw new __WEBPACK_IMPORTED_MODULE_5__errors_exception__["a" /* Exception */]("Unable to delete '" + key + "' from storage", error);
        }
    };
@sremiger1
Copy link
Author

Adding more details to the issue.

When getting an existing token that is expired it will attempt to delete said token and call get again which causes the circular reference

To fix simply rename
token.manager.ts get(provider: string): IToken {

to

token.manager.ts getValidToken(provider: string): IToken {

The get call within the delete then will call the proper get.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants