1
0
Fork 0
mirror of https://github.com/miawinter98/just-short-it.git synced 2024-11-22 08:19:54 +00:00

changed: migrated logout page to razor components

This commit is contained in:
Mia Rose Winter 2023-11-18 16:24:32 +01:00
parent 7b2b51f7a2
commit 2247031e11
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
4 changed files with 20 additions and 21 deletions

View file

@ -0,0 +1,19 @@
@page "/logout"
@using Microsoft.AspNetCore.Authentication
@using Microsoft.AspNetCore.Authentication.Cookies
@inject IHttpContextAccessor HttpContextAccessor;
@inject NavigationManager Navigation;
<PageTitle>Logout - Just Short It</PageTitle>
<p class="text-xl text-error">How did you get here?</p>
@code {
protected override async Task OnInitializedAsync() {
var context = HttpContextAccessor.HttpContext;
if (context is null) throw new ArgumentException("HttpContext");
await context.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
Navigation.NavigateTo("/", true);
}
}

View file

@ -1,8 +0,0 @@
@page
@model JustShortIt.Pages.LogoutModel
@{
ViewData["Title"] = "Logout";
}
<p class="text-xl text-error">How did you get here?</p>

View file

@ -1,13 +0,0 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace JustShortIt.Pages;
public class LogoutModel : PageModel {
public async Task<IActionResult> OnGetAsync() {
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return LocalRedirect("~/");
}
}

View file

@ -55,6 +55,7 @@
}); });
builder.Services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>(); builder.Services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();
builder.Services.AddCascadingAuthenticationState(); builder.Services.AddCascadingAuthenticationState();
builder.Services.AddHttpContextAccessor();
var app = builder.Build(); var app = builder.Build();