+
You're not logged in. Click the RecipeSage icon next to the address bar to
log in.
Note: If you don't see the RecipeSage icon next to the address bar, you
diff --git a/packages/webextension-v3/src/settings/settings.js b/packages/webextension-v3/src/settings/settings.js
index 65fa92cf5..87c8f1ffd 100644
--- a/packages/webextension-v3/src/settings/settings.js
+++ b/packages/webextension-v3/src/settings/settings.js
@@ -1,35 +1,53 @@
-const loggedInMessage = document.getElementById("loggedInMessage");
-const loggedOutMessage = document.getElementById("loggedOutMessage");
+const loggedInView = document.getElementById("loggedInView");
+const loggedOutView = document.getElementById("loggedOutView");
-chrome.storage.local.get(["token"], async (result) => {
+chrome.storage.local.get(["token", "api_url", "base_url"], async (result) => {
if (result.token) {
try {
const response = await fetch(
- `https://api.recipesage.com/users?token=${result.token}`,
+ `${result.api_url}users?token=${result.token}`,
);
const data = await response.json();
document.getElementById("loggedInEmail").innerText = data.email;
- loggedInMessage.style.display = "block";
+ document.getElementById("loggedInServer").innerText = result.api_url;
+ document.getElementById("baseUrl").value = result.base_url;
+ document.getElementById("apiUrl").value = result.api_url;
+ loggedInView.style.display = "block";
} catch (e) {
switch (e.status) {
case 401:
alert("There was an error while fetching your account data.");
break;
default:
- loggedOutMessage.style.display = "block";
+ loggedOutView.style.display = "block";
break;
}
}
} else {
- loggedOutMessage.style.display = "block";
+ loggedOutView.style.display = "block";
}
});
const logout = () => {
- chrome.storage.local.set({ token: null }, () => {
- loggedOutMessage.style.display = "block";
- loggedInMessage.style.display = "none";
+ chrome.storage.local.set(
+ { token: null, api_url: null, base_url: null },
+ () => {
+ loggedOutView.style.display = "block";
+ loggedInView.style.display = "none";
+ },
+ );
+};
+
+const updateServerDetails = () => {
+ const base_url = document.getElementById("baseUrl").value;
+ chrome.storage.local.set({ base_url }, () => {
+ document.getElementById("message").innerText =
+ "Your server details have been updated.";
+ setTimeout(() => {
+ document.getElementById("message").innerText = "";
+ }, 3000);
});
};
document.getElementById("logoutButton").onclick = logout;
+document.getElementById("serverDetailsUpdate").onclick = updateServerDetails;