Skip to content

Commit

Permalink
fix: fix avatar display and input disabled state (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamYSF authored Mar 4, 2024
1 parent 4e214af commit 18ee0db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function login() {
.getUserProfile(accessToken)
.then((userProfile) => displayUserProfile(userProfile));
});
setInputDisabledState(true, "endpoint", "applicationName")
} else {
alert("Login failed!");
}
Expand All @@ -49,6 +50,7 @@ function login() {
// eslint-disable-next-line no-unused-vars
function logout() {
chrome.storage.sync.set({accessToken: ""}, () => clearUserProfile());
setInputDisabledState(false, "endpoint", "applicationName")
}

function displayUserProfile(userProfile) {
Expand All @@ -63,3 +65,14 @@ function clearUserProfile() {
document.getElementById("user").innerHTML = "";
document.getElementById("loginOrLogout").innerText = "Login";
}

function setInputDisabledState(disabledState, ...elementIds) {
elementIds.forEach(elementId => {
const inputElement = document.getElementById(elementId);
if (inputElement) {
inputElement.disabled = disabledState;
} else {
console.warn(`No element found with ID: ${elementId}`);
}
});
}
1 change: 1 addition & 0 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ document.addEventListener("DOMContentLoaded", function() {
const managedAccounts = account.data.managedAccounts;
chrome.storage.sync.set({managedAccounts});
});
setInputDisabledState(true, "endpoint", "applicationName")
} else {
clearUserProfile();
}
Expand Down
2 changes: 1 addition & 1 deletion src/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Sdk {
getSignInUrl(clientId) {
const endpoint = this.config.endpoint;
const redirectUri = this.getRedirectUri();
const scope = "openid";
const scope = "profile";
const state = this.config.applicationName;
return `${endpoint}/login/oauth/authorize?client_id=${clientId}&response_type=token&redirect_uri=${redirectUri}&scope=${scope}&state=${state}`;
}
Expand Down

0 comments on commit 18ee0db

Please sign in to comment.