@@ -8,7 +8,7 @@ import type {
88import { EventEmitter } from '@herbcaudill/eventemitter42'
99import * as Auth from '@localfirst/auth'
1010import { hash } from '@localfirst/crypto'
11- import { debug , memoize , pause } from '@localfirst/shared'
11+ import { assert , debug , memoize , pause } from '@localfirst/shared'
1212import { type AbstractConnection } from './AbstractConnection.js'
1313import { AnonymousConnection } from './AnonymousConnection.js'
1414import { buildServerUrl } from './buildServerUrl.js'
@@ -211,7 +211,11 @@ export class AuthProvider extends EventEmitter<AuthProviderEvents> {
211211 * Creates a team and registers it with all of our sync servers.
212212 */
213213 public async createTeam ( teamName : string ) {
214- const team = await Auth . createTeam ( teamName , {
214+ if ( ! this . #user) {
215+ throw new Error ( 'Cannot create team as user is missing on AuthProvider' )
216+ }
217+
218+ const team = Auth . createTeam ( teamName , {
215219 device : this . #device,
216220 user : this . #user,
217221 } )
@@ -661,6 +665,10 @@ export class AuthProvider extends EventEmitter<AuthProviderEvents> {
661665
662666 const savedShares = unpack ( serializedState ) as SerializedState
663667
668+ if ( ! this . #user) {
669+ throw new Error ( 'Cannot load state as user is missing on AuthProvider' )
670+ }
671+
664672 await Promise . all (
665673 Object . values ( savedShares ) . map ( async share => {
666674 if ( 'encryptedTeam' in share ) {
@@ -672,9 +680,12 @@ export class AuthProvider extends EventEmitter<AuthProviderEvents> {
672680 this . #device. keys . secretKey
673681 ) as Auth . KeysetWithSecrets
674682
675- const context = { device : this . #device, user : this . #user }
683+ // By this point it is defined
684+ assert ( this . #user)
685+
686+ const context : Auth . LocalContext = { device : this . #device, user : this . #user }
676687
677- const team = await Auth . loadTeam ( encryptedTeam , context , teamKeys )
688+ const team = Auth . loadTeam ( encryptedTeam , context , teamKeys )
678689 return this . addTeam ( team )
679690 } else {
680691 return this . joinPublicShare ( share . shareId )
0 commit comments