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 autologin into nested interpreter #856

Closed
jcubic opened this issue Feb 2, 2023 · 2 comments
Closed

Allow to autologin into nested interpreter #856

jcubic opened this issue Feb 2, 2023 · 2 comments
Labels
feature resolved if issue is resolved, it will be open until merge with master

Comments

@jcubic
Copy link
Owner

jcubic commented Feb 2, 2023

I have an idea for a new feature for jQuery Terminal

When you have a nested interpreter that has login there is no way to autologic and no way to get the token and username for the interpreter that waits for authentication.

term.push(function(command) {

}, {
    login(user, password) {
         // ...
    }
});

There should be a way to skip the login when there are token and username is localstorage. But there should be a way to validate if token is valid first.

Possible solution:

term.push(function(command) {

}, {
    autologin(user, token) {
         // verify that the token is valid
         // and return a boolean or promise that resolves to boolean
    },
    login(user, password) {
         // ...
    }
});
@jcubic jcubic added the feature label Feb 2, 2023
@jcubic
Copy link
Owner Author

jcubic commented Feb 5, 2023

This is actually not needed, you can use:

 $('body').terminal(function(command, term) {
     
 }, {
     onBeforeLogin(user, token) {
         if (this.get_token() === token) {
             return false;
         }
     },
     login(user, password, cb) {
         return Promise.resolve('__TOKEN__');
     }
 });

onBeforeLogin execute after the user type user and password or before autologin.

But there was one problem that onBeforeLogin was supporting async call, so you were not able to return a promise and call the server to verify that the token was valid.

@jcubic
Copy link
Owner Author

jcubic commented Feb 5, 2023

Also, note that autologin happens automagically when refreshing the page and the interpreter has a token in localStorage.

@jcubic jcubic added the resolved if issue is resolved, it will be open until merge with master label Feb 5, 2023
jcubic added a commit that referenced this issue Feb 5, 2023
@jcubic jcubic closed this as completed Feb 6, 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