Skip to content

Commit

Permalink
fix(login): Persist API token on login
Browse files Browse the repository at this point in the history
  • Loading branch information
shantanuraj committed Dec 19, 2019
1 parent 8f32c37 commit f98e064
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/scripts/background.js
Expand Up @@ -1170,13 +1170,26 @@ window.TogglButton = {
browser.browserAction.setIcon({ path: imagePath });
},

setupToken: function (response) {
try {
const parsedResponse = JSON.parse(response);
const { api_token: apiToken } = parsedResponse.data;
localStorage.setItem('userToken', apiToken);
} catch (err) {
bugsnagClient.notify(new Error('Login token-parse failed'), {
metaData: { response }
});
}
},

loginUser: function (request) {
let error;
return new Promise((resolve, reject) => {
TogglButton.ajax('/sessions', {
method: 'POST',
onLoad: function (xhr) {
if (xhr.status === 200) {
TogglButton.setupToken(xhr.responseText);
TogglButton.queue.push(TogglButton.checkPermissions);
TogglButton.fetchUser()
.then((response) => {
Expand Down

0 comments on commit f98e064

Please sign in to comment.