Closed danijeljw-RPC closed 11 months ago
This function, will only ever return an email address to identify the user. This should be used to generate the in-house server-side data alone. Nothing else.
For this, assign the value in the /account/settings
page, and the save button will submit the data, and either create or update the record. Pass this along to Stripe when the user signs-up for a paid service plan too.
File _Host.cshtml
was original at https://github.com/repasscloud/AirAtlasPro/commit/e2acd8d90543eb484019bb69c41dfe4c012baafa
Boilerplate code for every default page in project:
@code {
private string pageTitle = "AirAtlasPro";
private bool showLogin = true;
private string Username = "Anonymous User";
private string Picture = string.Empty;
private bool? hasBillingRole;
private bool? hasSupportRole;
[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }
protected override async Task OnInitializedAsync()
{
if (authenticationState is not null)
{
var state = await authenticationState;
Username = state?.User?.Identity?.Name ?? string.Empty;
Picture = state?.User.Claims
.Where(c => c.Type.Equals("picture"))
.Select(c => c.Value)
.FirstOrDefault() ?? string.Empty;
hasBillingRole = state?.User.IsInRole("Billing");
hasSupportRole = state?.User.IsInRole("Support");
if (!string.IsNullOrEmpty(state?.User?.Identity?.Name))
{
showLogin = false;
}
}
await base.OnInitializedAsync();
}
// Redirect to login page if not already logged in
private void NavigateToLogin()
{
NavigationManager.NavigateTo("/login?redirectUri=/");
}
}
Boilerplate code for each page should also include:
@page "/<path>"
@attribute [Authorize]
@inject IJSRuntime JSRuntime
@inject ISupportTicketService SupportTicketService
@inject IToastService ToastService
@inject NavigationManager NavigationManager
<PageTitle>@pageTitle</PageTitle>
<h2>@pageTitle</h2>
@if (showLogin)
{
NavigateToLogin();
}
Full boilerplate code:
@page "/account/settings"
@attribute [Authorize]
@inject IJSRuntime JSRuntime
@inject ISupportTicketService SupportTicketService
@inject IToastService ToastService
@inject NavigationManager NavigationManager
<PageTitle>@pageTitle</PageTitle>
<h2>@pageTitle</h2>
@if (showLogin)
{
NavigateToLogin();
}
@*content goes here*@
@code {
private string pageTitle = "";
private User user = new User();
private bool showLogin = true;
private string Username = "Anonymous User";
private string Picture = string.Empty;
private bool? hasBillingRole;
private bool? hasSupportRole;
[CascadingParameter]
private Task<AuthenticationState>? authenticationState { get; set; }
protected override async Task OnInitializedAsync()
{
if (authenticationState is not null)
{
var state = await authenticationState;
Username = state?.User?.Identity?.Name ?? string.Empty;
Picture = state?.User.Claims
.Where(c => c.Type.Equals("picture"))
.Select(c => c.Value)
.FirstOrDefault() ?? string.Empty;
hasBillingRole = state?.User.IsInRole("Billing");
hasSupportRole = state?.User.IsInRole("Support");
if (!string.IsNullOrEmpty(state?.User?.Identity?.Name))
{
showLogin = false;
}
}
await base.OnInitializedAsync();
}
// Redirect to login page if not already logged in
private void NavigateToLogin()
{
NavigationManager.NavigateTo("/login?redirectUri=/");
}
@*additional functions go here*@
}
User sign-up and login functionality with secure authentication using Auth0