Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to overwrite JSON-RPC response value #883

Closed
jcubic opened this issue Jun 13, 2023 · 1 comment
Closed

Allow to overwrite JSON-RPC response value #883

jcubic opened this issue Jun 13, 2023 · 1 comment
Labels
feature resolved if issue is resolved, it will be open until merge with master

Comments

@jcubic
Copy link
Owner

jcubic commented Jun 13, 2023

I have an idea for a new feature for jQuery Terminal

So the idea is to allow hijacking the response from JSON-RPC and allow any async request and result of the user response will be processed. Not only allow mutating the response.

This is needed to create a seamless experience using JWT refresh token (issue #829).

When the user type a command and it throws an error because the access token expires, you should be able to send a new HTTP request or new JSON-RPC call to refresh the token and save a new access token in localStorage:

Not sure how to simplify the API. Maybe there is a need for a new handler that will replace response and request single event that will get request and response objects and return a new response asynchronously.

$('body').terminal('service.php', {
    rpc(req, res) {
        if (res.error && res.error.message === 'Access token expired') {
            return new Promise(resolve => {
                $.jrpc('service.php', 'refresh', [], (message) => {
                    const new_token = message.result;
                    this.set_token(new_token);
                    req.params[0] = new_token;
                    $.jrpc('service.php', req.method, req.params, resolve);
                });
            });
        }
    }
}, {
  login: true
});

Right now when the token expired there is a visible error on the terminal.

@jcubic jcubic added the feature label Jun 13, 2023
@jcubic jcubic changed the title Allow to overwrite response value Allow to overwrite JSON-RPC response value Jun 13, 2023
jcubic added a commit that referenced this issue Jun 28, 2023
@jcubic jcubic added the resolved if issue is resolved, it will be open until merge with master label Jun 28, 2023
@jcubic
Copy link
Owner Author

jcubic commented Jul 30, 2023

Released in 2.37.0

@jcubic jcubic closed this as completed Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature resolved if issue is resolved, it will be open until merge with master
Projects
None yet
Development

No branches or pull requests

1 participant