-
Notifications
You must be signed in to change notification settings - Fork 373
feat(web): auth-gate code search submit on Ask GH #1680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
db7ad83
4eb199c
4206633
8a66f07
f7fec32
95840f4
81846d3
e372c86
4e6cd96
2e89fd5
af0419c
f12f179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ import Link from "next/link"; | |
| import { CaseSensitiveIcon, RegexIcon, Wand2Icon } from "lucide-react"; | ||
| import { SearchAssistBox } from "./searchAssistBox"; | ||
| import useCaptureEvent from "@/hooks/useCaptureEvent"; | ||
| import { LoginDialog } from "@/app/components/loginDialog"; | ||
|
|
||
| const LANGUAGE_MODEL_DOCS_URL = "https://docs.sourcebot.dev/docs/configuration/language-model-providers"; | ||
|
|
||
|
|
@@ -60,6 +61,7 @@ interface SearchBarProps { | |
| } | ||
| autoFocus?: boolean; | ||
| isSearchAssistSupported: boolean; | ||
| showLoginWall: boolean; | ||
| } | ||
|
|
||
| const searchBarKeymap: readonly KeyBinding[] = ([ | ||
|
|
@@ -107,6 +109,7 @@ export const SearchBar = ({ | |
| query: defaultQuery = "", | ||
| } = {}, | ||
| isSearchAssistSupported, | ||
| showLoginWall, | ||
| }: SearchBarProps) => { | ||
| const router = useRouter(); | ||
| const captureEvent = useCaptureEvent(); | ||
|
|
@@ -120,6 +123,7 @@ export const SearchBar = ({ | |
| const [isHistorySearchEnabled, setIsHistorySearchEnabled] = useState(false); | ||
| const [isRegexEnabled, setIsRegexEnabled] = useState(defaultIsRegexEnabled); | ||
| const [isCaseSensitivityEnabled, setIsCaseSensitivityEnabled] = useState(defaultIsCaseSensitivityEnabled); | ||
| const [loginCallbackUrl, setLoginCallbackUrl] = useState<string>(); | ||
|
|
||
| const focusEditor = useCallback(() => editorRef.current?.view?.focus(), []); | ||
| const focusSuggestionsBox = useCallback(() => suggestionBoxRef.current?.focus(), []); | ||
|
|
@@ -230,8 +234,24 @@ export const SearchBar = ({ | |
| [SearchQueryParams.isRegexEnabled, isRegexEnabled ? "true" : null], | ||
| [SearchQueryParams.isCaseSensitivityEnabled, isCaseSensitivityEnabled ? "true" : null], | ||
| ); | ||
|
|
||
| if (showLoginWall) { | ||
| if (query.trim().length === 0) { | ||
| return; | ||
| } | ||
| captureEvent('wa_publicsaas_cs_login_wall_prompted', {}); | ||
| setLoginCallbackUrl(url); | ||
| return; | ||
| } | ||
|
|
||
| router.push(url); | ||
| }, [router, isRegexEnabled, isCaseSensitivityEnabled]); | ||
| }, [ | ||
| captureEvent, | ||
| isCaseSensitivityEnabled, | ||
| isRegexEnabled, | ||
| router, | ||
| showLoginWall, | ||
| ]); | ||
|
|
||
| return ( | ||
| <div | ||
|
|
@@ -401,6 +421,15 @@ export const SearchBar = ({ | |
| cursorPosition={cursorPosition} | ||
| {...suggestionData} | ||
| /> | ||
| <LoginDialog | ||
| isOpen={loginCallbackUrl !== undefined} | ||
| onOpenChange={(open) => { | ||
| if (!open) { | ||
| setLoginCallbackUrl(undefined); | ||
| } | ||
| }} | ||
| callbackUrl={loginCallbackUrl} | ||
| /> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Login form Enter key interceptedMedium Severity
Additional Locations (1)Reviewed by Cursor Bugbot for commit f12f179. Configure here. |
||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { env } from "@sourcebot/shared"; | ||
| import { auth } from "@/auth"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: Use Prompt for AI agents |
||
| import { SearchLandingPage } from "./components/searchLandingPage"; | ||
| import { SearchResultsPage } from "./components/searchResultsPage"; | ||
| import { getConfiguredLanguageModelsInfo } from "@/features/chat/utils.server"; | ||
|
|
@@ -16,12 +17,19 @@ export default async function SearchPage(props: SearchPageProps) { | |
| const query = searchParams?.query; | ||
| const isRegexEnabled = searchParams?.isRegexEnabled === "true"; | ||
| const isCaseSensitivityEnabled = searchParams?.isCaseSensitivityEnabled === "true"; | ||
| const session = await auth(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: set -eu
printf '%s\n' '--- candidate files ---'
fd -i -t f '(^page\.tsx$|authenticatedPage|layout\.tsx$|README\.md$)' packages/web/src/app packages/web/src/middleware | sed -n '1,120p'
printf '%s\n' '--- search page ---'
cat -n 'packages/web/src/app/(app)/search/page.tsx'
printf '%s\n' '--- authenticatedPage references ---'
rg -n -C 8 'authenticatedPage' packages/web/src/middleware packages/web/src/app/'(app)' | sed -n '1,240p'
printf '%s\n' '--- auth wrapper source candidates ---'
fd -i -t f . packages/web/src/middleware | sort | sed -n '1,160p'Repository: sourcebot-dev/sourcebot Length of output: 26711 🏁 Script executed: set -eu
printf '%s\n' '--- search page ---'
cat -n 'packages/web/src/app/(app)/search/page.tsx'
printf '%s\n' '--- authentication references ---'
rg -n -C 8 'authenticatedPage|export.*auth|function auth|const auth' packages/web/src/middleware packages/web/src/app/'(app)' | sed -n '1,260p'
printf '%s\n' '--- middleware files ---'
fd -i -t f . packages/web/src/middleware | sortRepository: sourcebot-dev/sourcebot Length of output: 23101 🏁 Script executed: set -eu
printf '%s\n' '--- authenticatedPage implementation ---'
cat -n packages/web/src/middleware/authenticatedPage.tsx | sed -n '1,125p'
printf '%s\n' '--- route-group layout ---'
cat -n 'packages/web/src/app/(app)/layout.tsx' | sed -n '1,180p'Repository: sourcebot-dev/sourcebot Length of output: 13569 Use
Suggested fix-import { auth } from "`@/auth`";
+import { authenticatedPage, type OptionalAuthOptions } from "`@/middleware/authenticatedPage`";
...
-interface SearchPageProps {
+interface SearchPageProps extends Record<string, unknown> {
...
-export default async function SearchPage(props: SearchPageProps) {
+export default authenticatedPage<SearchPageProps, OptionalAuthOptions>(async ({ user }, props) => {
...
- const session = await auth();
- const showLoginWall = env.EXPERIMENT_ASK_GH_ENABLED === "true" && !session?.user;
+ const showLoginWall = env.EXPERIMENT_ASK_GH_ENABLED === "true" && !user;
...
-}
+}, { allowAnonymous: true });🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| const showLoginWall = env.EXPERIMENT_ASK_GH_ENABLED === "true" && !session?.user; | ||
|
|
||
| const languageModels = await getConfiguredLanguageModelsInfo(); | ||
| const isSearchAssistSupported = languageModels.length > 0; | ||
|
|
||
| if (query === undefined || query.length === 0) { | ||
| return <SearchLandingPage isSearchAssistSupported={isSearchAssistSupported} /> | ||
| return ( | ||
| <SearchLandingPage | ||
| isSearchAssistSupported={isSearchAssistSupported} | ||
| showLoginWall={showLoginWall} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
|
|
@@ -31,6 +39,7 @@ export default async function SearchPage(props: SearchPageProps) { | |
| isRegexEnabled={isRegexEnabled} | ||
| isCaseSensitivityEnabled={isCaseSensitivityEnabled} | ||
| isSearchAssistSupported={isSearchAssistSupported} | ||
| showLoginWall={showLoginWall} | ||
| /> | ||
| ) | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Anonymous empty submissions no longer navigate to the search landing page: this early return leaves the previous results URL and results visible after the user clears the query and presses Enter. Gate only non-empty queries, then let empty submissions fall through to the existing
router.push(url).Prompt for AI agents