mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Pass onAuth into the git constructor instead of to push method
This commit is contained in:
6 files changed
+19
-37
No files matched your search
@@ -93,6 +93,7 @@ describe('useGit', () => {
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://cors.isomorphic-git.org',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
onAuth: expect.any(Function),
|
||||
});
|
||||
expect(result.current).toEqual({ git: expect.any(Object) });
|
||||
});
|
||||
@@ -107,6 +108,7 @@ describe('useGit', () => {
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://custom-cors.example.com',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
onAuth: expect.any(Function),
|
||||
});
|
||||
expect(result.current).toEqual({ git: expect.any(Object) });
|
||||
});
|
||||
@@ -121,6 +123,7 @@ describe('useGit', () => {
|
||||
nostr: mockNostr,
|
||||
corsProxy: 'https://cors.isomorphic-git.org',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
onAuth: expect.any(Function),
|
||||
});
|
||||
|
||||
// Rerender with a different wrapper (different CORS proxy)
|
||||
|
||||
+10
-3
@@ -1,8 +1,10 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { Git } from '@/lib/git';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { findCredentialsForRepo } from '@/lib/gitCredentials';
|
||||
import { useGitSettings } from './useGitSettings';
|
||||
|
||||
/**
|
||||
* Hook that provides a Git instance configured with the virtual filesystem
|
||||
@@ -12,6 +14,7 @@ export function useGit(): { git: Git } {
|
||||
const { fs } = useFS();
|
||||
const { nostr } = useNostr();
|
||||
const { config } = useAppContext();
|
||||
const { settings } = useGitSettings();
|
||||
const { corsProxy, graspMetadata } = config;
|
||||
|
||||
const ngitServers = useMemo(() => {
|
||||
@@ -26,9 +29,13 @@ export function useGit(): { git: Git } {
|
||||
}).filter((hostname): hostname is string => Boolean(hostname));
|
||||
}, [graspMetadata.relays]);
|
||||
|
||||
const onAuth = useCallback((url: string) => {
|
||||
return findCredentialsForRepo(url, settings.credentials);
|
||||
}, [settings.credentials]);
|
||||
|
||||
const git = useMemo(() => {
|
||||
return new Git({ fs, nostr, corsProxy, ngitServers });
|
||||
}, [fs, nostr, corsProxy, ngitServers]);
|
||||
return new Git({ fs, nostr, corsProxy, ngitServers, onAuth });
|
||||
}, [fs, nostr, corsProxy, ngitServers, onAuth]);
|
||||
|
||||
return { git };
|
||||
}
|
||||
Reference in new issue
Block a user