Skip to content

Commit

Permalink
Merge pull request #118 from local-first-web/sync-server-no-peerid
Browse files Browse the repository at this point in the history
Stop passing a peerId when creating a Repo
  • Loading branch information
HerbCaudill authored Sep 21, 2024
2 parents 6ab7e9c + 2fa05a8 commit 1860209
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
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

0 comments on commit 1860209

Please sign in to comment.