MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / useFetchLoginUrl

Function useFetchLoginUrl

cli/src/hooks/use-fetch-login-url.ts:20–62  ·  view source on GitHub ↗
({
  setLoginUrl,
  setFingerprintHash,
  setExpiresAt,
  setIsWaitingForEnter,
  setHasOpenedBrowser,
  setError,
}: UseFetchLoginUrlParams)

Source from the content-addressed store, hash-verified

18 * Custom hook that handles fetching the login URL and opening the browser
19 */
20export function useFetchLoginUrl({
21 setLoginUrl,
22 setFingerprintHash,
23 setExpiresAt,
24 setIsWaitingForEnter,
25 setHasOpenedBrowser,
26 setError,
27}: UseFetchLoginUrlParams) {
28 const fetchLoginUrlMutation = useMutation({
29 mutationFn: async (fingerprintId: string) => {
30 return generateLoginUrl(
31 {
32 logger,
33 },
34 {
35 baseUrl: LOGIN_WEBSITE_URL,
36 fingerprintId,
37 },
38 )
39 },
40 onSuccess: async (data) => {
41 setLoginUrl(data.loginUrl)
42 setFingerprintHash(data.fingerprintHash)
43 setExpiresAt(data.expiresAt)
44 setIsWaitingForEnter(true)
45 setHasOpenedBrowser(true)
46
47 // Open browser after fetching URL
48 await safeOpen(data.loginUrl)
49 },
50 onError: (err) => {
51 setError(err instanceof Error ? err.message : 'Failed to get login URL')
52 logger.error(
53 {
54 error: err instanceof Error ? err.message : String(err),
55 },
56 'Failed to get login URL',
57 )
58 },
59 })
60
61 return fetchLoginUrlMutation
62}

Callers 1

LoginModalFunction · 0.90

Calls 3

generateLoginUrlFunction · 0.90
safeOpenFunction · 0.90
setErrorFunction · 0.85

Tested by

no test coverage detected