u/7H36

▲ 5 r/Blazor

Microsoft Identity with Blazor Server?

Hi, I'm new to blazor and I'm currently on the account authentication phase of my project, the problem I keep getting for weeks now is the non restful login/logout accounts of my blazor server. The only solution I could think of is to make a condition based on the user's url:

    @* Apply the dynamic render mode here *@
    <HeadOutlet @rendermode="CurrentRenderMode" />
</head>
<body>
    @* Apply the dynamic render mode here *@
    <Routes @rendermode="CurrentRenderMode" />

    private IComponentRenderMode? CurrentRenderMode
    {
        get
        {
            // Get the current path (e.g., "login", "account/register", or "")
            var path = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLower();

            // If the user is on the Login page or any Account page, render STATICALLY (null)
            if (path.StartsWith("account"))
            {
                return null;
            }

            // For all other pages (Home, Admin, etc.), render INTERACTIVELY so MudBlazor works
            return InteractiveServer;
        }
    }

But the problem with this is while there's no SignalR connection on a static SSR, component's such as burger menu collapse, toggle theme, etc, won't work since there's no active connection to interact, only if I switch to an InteractiveServer.

Is this fine? I feel like there's a better approach here. Please excuse my naivity. Thank you!

reddit.com
u/7H36 — 6 days ago