Skip to content

Commit 2b1e124

Browse files
committed
Fix issue with api key being deleted from storage
Fixed or at least subdued bug that was causing the stored api key to be cleared.
1 parent 803592e commit 2b1e124

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

js/app-view-model.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function AppViewModel() {
104104
floatinSearchField.style.zIndex = '-9999';
105105

106106
const apiKey = document.getElementById('api-key');
107-
apiKey.value = localStorage.getItem("gptKey") || "";
107+
apiKey.value = localStorage.getItem("gptKey");
108108

109109
apiKey.addEventListener("blur", () => {
110110
if (apiKey.value.trim() !== "")
@@ -208,6 +208,11 @@ export function AppViewModel() {
208208

209209
self.toggleSidebar = () => {
210210
self.isSidebarOpen(!self.isSidebarOpen());
211+
212+
if (self.isSidebarOpen()) {
213+
const apiKey = document.getElementById('api-key');
214+
apiKey.value = localStorage.getItem("gptKey");
215+
}
211216
};
212217

213218
const messagesContainer = document.getElementById("messagesContainer");

js/storage.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const apiKey = document.getElementById('api-key');
2-
apiKey.value = localStorage.getItem("gptKey") || "";
2+
apiKey.value = localStorage.getItem("gptKey");
33

44
export async function fetchGPTResponse(conversation, attitude, model) {
55
const prompt = `Me: ${conversation}\nAI:`;
66
let storedApiKey = localStorage.getItem("gptKey");
77

8-
if (storedApiKey !== apiKey.value.trim()) {
9-
localStorage.setItem("gptKey", apiKey.value.trim());
10-
storedApiKey = apiKey.value.trim();
11-
}
8+
// if (storedApiKey !== apiKey.value.trim()) {
9+
// localStorage.setItem("gptKey", apiKey.value.trim());
10+
// storedApiKey = apiKey.value.trim();
11+
// }
1212

1313
if (!localStorage.getItem("gpt-attitude") || localStorage.getItem("gpt-attitude") !== attitude) {
1414
localStorage.setItem("gpt-attitude", attitude);
@@ -44,10 +44,10 @@ export async function fetchGPTResponse(conversation, attitude, model) {
4444
export async function generateDALLEImage(conversation) {
4545
let storedApiKey = localStorage.getItem("gptKey");
4646

47-
if (storedApiKey !== apiKey.value.trim()) {
48-
localStorage.setItem("gptKey", apiKey.value.trim());
49-
storedApiKey = apiKey.value.trim();
50-
}
47+
// if (storedApiKey !== apiKey.value.trim()) {
48+
// localStorage.setItem("gptKey", apiKey.value.trim());
49+
// storedApiKey = apiKey.value.trim();
50+
// }
5151

5252
try {
5353
const response = await fetch("https://api.openai.com/v1/images/generations", {

js/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function wrapCodeSnippets(input) {
1818
export async function getConversationTitleFromGPT(messages, model, sliderValue) {
1919
try {
2020
const apiKey = document.getElementById('api-key');
21-
apiKey.value = localStorage.getItem("gptKey") || "";
21+
apiKey.value = localStorage.getItem("gptKey");
2222

2323
let tempMessages = messages.slice(0);
2424
tempMessages.push({ role: 'user', content: "Summarize our conversation in 5 words or less." });

0 commit comments

Comments
 (0)