protected async override Task OnInitializedAsync() { var token = UserState.UserContext.AccessToken; HubConnection = new HubConnectionBuilder() .WithUrl(NavigationManager.ToAbsoluteUri(Common.Global.Constants.Hubs.NotificationHub), options => { options.AccessTokenProvider = () => Task.FromResult(token); }) .Build(); HubConnection.On <NotificationModel>(Common.Global.Constants.Hubs.ReceiveMessage, (model) => { ReceivedNotifications.Add(model); ToastService.ShowInfo(model.Message); StateHasChanged(); }); await HubConnection.StartAsync(); }
protected async override Task OnInitializedAsync() { var accessToken = await this.AccessTokenProvider.RequestAccessToken(); if (accessToken.TryGetToken(out var token)) { HubConnection = new HubConnectionBuilder() .WithUrl(NavigationManager.ToAbsoluteUri(Common.Global.Constants.Hubs.NotificationHub), options => { options.AccessTokenProvider = () => Task.FromResult(token.Value); }) .Build(); HubConnection.On <NotificationModel>(Common.Global.Constants.Hubs.ReceiveMessage, (model) => { ReceivedNotifications.Add(model); ToastifyService.DisplayInformationNotification(model.Message); StateHasChanged(); }); await HubConnection.StartAsync(); } }