diff --git a/packages/core/src/services/user-manager/const.ts b/packages/core/src/services/user-manager/const.ts index f83ff3a2146..fb571614abf 100644 --- a/packages/core/src/services/user-manager/const.ts +++ b/packages/core/src/services/user-manager/const.ts @@ -25,7 +25,16 @@ const nameMap = { [UnitRole.Reader]: 'Reader', [UnitRole.UNRECOGNIZED]: 'UNRECOGNIZED', }; -export const createDefaultUser = (type: UnitRole) => { +export const createDefaultUser = (type?: UnitRole) => { + if (!type) { + return { + userID: '', + name: '', + avatar: '', + anonymous: true, + canBindAnonymous: false, + } as IUser; + } const user = { userID: `${nameMap[type]}_${Tools.generateRandomId(8)}`, name: nameMap[type], diff --git a/packages/core/src/services/user-manager/user-manager.service.ts b/packages/core/src/services/user-manager/user-manager.service.ts index f50a49fad84..fe5205c7712 100644 --- a/packages/core/src/services/user-manager/user-manager.service.ts +++ b/packages/core/src/services/user-manager/user-manager.service.ts @@ -15,7 +15,6 @@ */ import type { IUser } from '@univerjs/protocol'; -import { UnitRole } from '@univerjs/protocol'; import { BehaviorSubject, Subject } from 'rxjs'; import { LifecycleStages, OnLifecycle } from '../lifecycle/lifecycle'; @@ -26,7 +25,7 @@ export class UserManagerService { private _model = new Map(); private _userChange$ = new Subject<{ type: 'add' | 'delete'; user: IUser } | { type: 'clear' }>(); public userChange$ = this._userChange$.asObservable(); - private _currentUser$ = new BehaviorSubject(createDefaultUser(UnitRole.Owner)); + private _currentUser$ = new BehaviorSubject(createDefaultUser()); /** * When the current user undergoes a switch or change * @memberof UserManagerService