Skip to content
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

Stop passing a peerId when creating a Repo #118

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/auth-syncserver/src/SyncServer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Repo, type PeerId } from '@automerge/automerge-repo'
import { Repo } from '@automerge/automerge-repo'
import { NodeWSServerAdapter } from '@automerge/automerge-repo-network-websocket'
import { NodeFSStorageAdapter } from '@automerge/automerge-repo-storage-nodefs'
import {
Expand Down Expand Up @@ -85,14 +85,12 @@ export class LocalFirstAuthSyncServer {
const server: ServerWithSecrets = { host: this.host, keys }
const user = castServer.toUser(server)
const device = castServer.toDevice(server)
const peerId = this.host as PeerId
const storage = new NodeFSStorageAdapter(storageDir)
const auth = new AuthProvider({ user, device, storage })

// Set up the repo
const adapter = new NodeWSServerAdapter(this.webSocketServer)
const _repo = new Repo({
peerId,
// Use the auth provider to wrap our network adapter
network: [auth.wrap(adapter)],
// Use the same storage that the auth provider uses
Expand Down
7 changes: 3 additions & 4 deletions packages/auth-syncserver/src/test/SyncServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ it('Alice can create a team', async () => {

// when we're authenticated, we get a peer event
const { peerId } = await eventPromise(alice.repo.networkSubsystem, 'peer')
expect(peerId).toEqual(host)
expect(peerId.length).toBeGreaterThan(0)
})

it('Alice can create a team and manually register it with the server ', async () => {
Expand Down Expand Up @@ -68,7 +68,7 @@ it('Alice can create a team and manually register it with the server ', async ()

// when we're authenticated, we get a peer event
const { peerId } = await eventPromise(alice.repo.networkSubsystem, 'peer')
expect(peerId).toEqual(host)
expect(peerId.length).toBeGreaterThan(0)
})

// // TODO NEXT figure out how to make this test reflect reality & crash
Expand Down Expand Up @@ -131,8 +131,7 @@ it(`Eve can't replace the team on the sync server`, async () => {
body: JSON.stringify({ serializedGraph, teamKeyring }),
})

const { peerId } = await eventPromise(alice.repo.networkSubsystem, 'peer')
expect(peerId).toEqual(host)
await eventPromise(alice.repo.networkSubsystem, 'peer')

// Eve tries to re-register the team with the server

Expand Down
Loading