Skip to content

Commit 47c6a50

Browse files
committed
fix: clear stale auth state on repo change
1 parent d80188f commit 47c6a50

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/app/generate/GeneratePageClient.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ export default function GeneratePageClient({ repoSlug }: GeneratePageProps) {
4848
});
4949

5050
if (!response.ok) {
51-
let errorMessage: string;
51+
let extractedMessage: string;
5252
let requiresAuth = false;
5353
const contentType = response.headers.get("content-type") || "";
5454

5555
if (contentType.includes("application/json")) {
5656
const errorData = await response.json();
57-
errorMessage =
57+
extractedMessage =
5858
errorData.message || errorData.error || response.statusText;
5959
requiresAuth = Boolean(errorData.authRequired);
6060
setPrivateRepoConsentRequired(
@@ -63,12 +63,12 @@ export default function GeneratePageClient({ repoSlug }: GeneratePageProps) {
6363
} else {
6464
const errorText = await response.text();
6565
console.error("Non-JSON error response from /api/generate:", errorText);
66-
errorMessage =
66+
extractedMessage =
6767
"The server hit an unexpected error while generating the README. Please try again, and check the local server logs if it keeps happening.";
6868
}
6969

7070
setAuthRequired(requiresAuth);
71-
throw new Error(errorMessage);
71+
throw new Error(extractedMessage);
7272
}
7373

7474
const data = await response.json();
@@ -90,8 +90,10 @@ export default function GeneratePageClient({ repoSlug }: GeneratePageProps) {
9090
}
9191
};
9292

93-
const clearPrivateRepoConsent = () => {
93+
const clearGenerateFormState = () => {
9494
setPrivateRepoConsentRequired(false);
95+
setErrorMessage(null);
96+
setAuthRequired(false);
9597
};
9698

9799
return (
@@ -112,7 +114,7 @@ export default function GeneratePageClient({ repoSlug }: GeneratePageProps) {
112114
serverError={errorMessage}
113115
authRequired={authRequired}
114116
privateRepoConsentRequired={privateRepoConsentRequired}
115-
onClearPrivateRepoConsent={clearPrivateRepoConsent}
117+
onClearPrivateRepoConsent={clearGenerateFormState}
116118
/>
117119
<MarkdownPreview content={markdown} />
118120
</main>

src/components/Generator/SearchInput.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export const SearchInput = ({
9292
value={url}
9393
onChange={(e) => {
9494
setUrl(e.target.value);
95-
if (privateRepoConsentRequired) {
95+
if (
96+
privateRepoConsentRequired ||
97+
authRequired ||
98+
Boolean(serverError)
99+
) {
96100
onClearPrivateRepoConsent();
97101
}
98102
if (ackPrivateRepo) {

0 commit comments

Comments
 (0)