C#C
C#2y ago
Bordin

✅ SignalR Authorized Connection

namespace LebUpwork.Api.Hubs
{
    //[Authorize] <- This causes error when connecting 
    public class NotificationHub : Hub<INotification>
    {
        public override async Task OnConnectedAsync()
        {
           await Clients.Client(Context.ConnectionId).ReceiveNotification($"Thank you for connecting {Context.User?.Identity.Name}");
           await base.OnConnectedAsync();
        }
    }
    
}

hello, i am initiating a connection on this Hub, however when i add [Authorized] the connection is failing
const connection = new HubConnectionBuilder()
        .withUrl("https://localhost:7170/Hubs/NotificationHub", {
          accessTokenFactory: () => token,
          skipNegotiation: true,
          transport: HttpTransportType.WebSockets,
        })
        .build();

even tho I am adding the accessTokenFactory. Am i doing something wrong?
Was this page helpful?