mattermost / mattermost-redux

Redux for Mattermost
Apache License 2.0
200 stars 386 forks source link

Login does not save token #1359

Closed saitho closed 2 years ago

saitho commented 3 years ago

Summary

Calling the "login" method does not set the token (anymore?). The example in the readme suggests that it should:

client.setUrl('https://your-mattermost-url.com');
client.login(username, password)
.then(function(me){
    console.log(`logged in as ${me.email}`);
    token = client.getToken(); // empty!
})

Steps to reproduce

Execute the example code with valid server URL and credentials (username and password).

Expected behavior

I expect the token to be stored in the client. If the login is done with a password, the token received from Mattermost server in response header should be saved. If the login is done with a token, the used token should be saved.

Observed behavior

Subsequent API actions want me to authenticate again. I can't use the API using this library with username and password.

Possible fixes

I guess somewhere around https://github.com/mattermost/mattermost-redux/blob/master/src/client/client4.ts#L658, but I don't know where to get the response header.

My current workaround: Send a separate login via Axios to get the token.