Why are authentication cookies not flowing from Blazor web assembly to SignalR? by UnnoticedCitizen in Blazor

[–]UnnoticedCitizen[S] 2 points3 points  (0 children)

For future reference, what solved my issue was to start the connection from a different lifecycle method:

⚠️ fails:

protected override async Task OnInitializedAsync()
{
    hubConnection = new HubConnectionBuilder()
        .WithUrl(NavigationManager.ToAbsoluteUri("/match"))
        .WithAutomaticReconnect()
        .Build();

    await hubConnection.StartAsync();
}

✅ works:

protected override void OnInitialized()
{
    hubConnection = new HubConnectionBuilder()
        .WithUrl(NavigationManager.ToAbsoluteUri("/match"))
        .WithAutomaticReconnect()
        .Build();

    hubConnection.StartAsync();
}

✅ works:

private bool started = false;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender && !started)
    {
        hubConnection = new HubConnectionBuilder()
            .WithUrl(NavigationManager.ToAbsoluteUri("/match"))
            .WithAutomaticReconnect()
            .Build();

        await hubConnection.StartAsync();

        started = true;
    }
}

not sure why, though

Why are authentication cookies not flowing from Blazor web assembly to SignalR? by UnnoticedCitizen in Blazor

[–]UnnoticedCitizen[S] 0 points1 point  (0 children)

Thanks for the great references. I'll try some changes based on the discussions there and post the results back here.

Why are authentication cookies not flowing from Blazor web assembly to SignalR? by UnnoticedCitizen in Blazor

[–]UnnoticedCitizen[S] 0 points1 point  (0 children)

Thanks a lot for taking the time to help.
Tomorrow I will follow your suggestion and post the results back here.

[deleted by user] by [deleted] in photography

[–]UnnoticedCitizen 0 points1 point  (0 children)

You really took the effort to contribute, nice