Skip to content

Instantly share code, notes, and snippets.

@mattruma
Created July 3, 2020 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattruma/e4cc5dce47894f4edb12c18f37aebfca to your computer and use it in GitHub Desktop.
Save mattruma/e4cc5dce47894f4edb12c18f37aebfca to your computer and use it in GitHub Desktop.
Adventures with Blazor: Login and Logout Events
@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using System.Threading.Tasks
<RemoteAuthenticatorView Action="@Action" OnLogOutSucceeded=@this.OnLogOutSucceeded OnLogInSucceeded=@this.OnLogInSucceeded />
@code{
[Parameter]
public string Action { get; set; }
[CascadingParameter]
public Task<AuthenticationState> AuthenticationState { get; set; }
public async void OnLogInSucceeded()
{
var user =
(await AuthenticationState).User;
if (user.Identity.IsAuthenticated)
{
// Do some stuff
}
}
public void OnLogOutSucceeded()
{
// Do some stuff
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment