Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blazor][Wasm] Topic for prerendering and auth #17648

Closed
javiercn opened this issue Apr 7, 2020 · 4 comments
Closed

[Blazor][Wasm] Topic for prerendering and auth #17648

javiercn opened this issue Apr 7, 2020 · 4 comments

Comments

@javiercn
Copy link
Member

javiercn commented Apr 7, 2020

Content

Steps for supporting auth + prerendering on Blazor applications.

  • The app will prerender paths for which authorization is not required.
  • Paths for which authorization is required will not be prerendered.
  1. On your Client/Program.cs factor common service registrations into a separate method.
  2. On your Server/Startup.cs register the services required for the UI and the applicaation to work.
services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();
services.AddScoped<SignOutSessionStateManager>();

Client.Program.ConfigureCommonServices(services);

Replace endpoints.MapFallbackToFile("index.html") with endpoints.MapFallbackToPage("/_Host")
3. Create a _Host.cshtml page inside the pages directory, paste the contents from index.html into it and replace the <app>Loading...</app> tag with the following:

<app>
    @if (!HttpContext.Request.Path.StartsWithSegments("/authentication"))
    {
        <component type="typeof(Wasm.Authentication.Client.App)" render-mode="Static" />
    }
    else
    {
        <text>Loading...</text>
    }
</app>
@guardrex
Copy link
Collaborator

guardrex commented Apr 7, 2020

@MeysamMoghaddam
Copy link

how to handle api AuthenticationStateProvider in blazor wasm prerender .NET 5 Release Candidate 1 ?

ezgif com-video-to-gif

and in Blazor WebAssembly prerendering :
dotnet/aspnetcore#26094

@MeysamMoghaddam
Copy link

how to handle api AuthenticationStateProvider in blazor wasm prerender .NET 5 Release Candidate 1 ?

ezgif com-video-to-gif

and in Blazor WebAssembly prerendering :
dotnet/aspnetcore#26094

Tnx
Resolved This Issue:
in "app" component not work tag when use ApiAuthenticationStateProvider.
I used
`var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;

        if (!user.Identity.IsAuthenticated)
        {
        }

`
in OnAfterRenderAsync Method

@ChristianWeyer
Copy link

Do you have your sample and the solution somewhere available in Github? @MeysamMoghaddam ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants