diff --git a/projects/stream-chat-angular/src/lib/chat-client.service.ts b/projects/stream-chat-angular/src/lib/chat-client.service.ts index 769c3181..86b57655 100644 --- a/projects/stream-chat-angular/src/lib/chat-client.service.ts +++ b/projects/stream-chat-angular/src/lib/chat-client.service.ts @@ -84,13 +84,17 @@ export class ChatClientService< * Creates a [`StreamChat`](https://github.com/GetStream/stream-chat-js/blob/668b3e5521339f4e14fc657834531b4c8bf8176b/src/client.ts#L124) instance using the provided `apiKey`, and connects a user with the given meta data and token. More info about [connecting users](https://getstream.io/chat/docs/javascript/init_and_users/?language=javascript) can be found in the platform documentation. * @param apiKey * @param userOrId - * @param userTokenOrProvider You can provide a token, or the keyword 'guest' to connect as [guest user](https://getstream.io/chat/docs/javascript/authless_users/?language=javascript#guest-users) + * @param userTokenOrProvider You can provide: * @param clientOptions Setting to provide to the Stream client instance */ async init( apiKey: string, userOrId: string | OwnUserResponse | UserResponse, - userTokenOrProvider: TokenOrProvider | 'guest', + userTokenOrProvider: TokenOrProvider | 'anonymous' | 'guest', clientOptions?: StreamChatOptions ): ConnectAPIResponse { this.chatClient = StreamChat.getInstance(apiKey, clientOptions); @@ -99,10 +103,13 @@ export class ChatClientService< await this.ngZone.runOutsideAngular(async () => { const user = typeof userOrId === 'string' ? { id: userOrId } : userOrId; try { - result = - userTokenOrProvider === 'guest' - ? await this.chatClient.setGuestUser(user) - : await this.chatClient.connectUser(user, userTokenOrProvider); + result = await ( + { + guest: () => this.chatClient.setGuestUser(user), + anonymous: () => this.chatClient.connectAnonymousUser(), + }[`${userTokenOrProvider}`] ?? + (() => this.chatClient.connectUser(user, userTokenOrProvider)) + )(); } catch (error) { this.notificationService.addPermanentNotification( 'streamChat.Error connecting to chat, refresh the page to try again.',