mirror of
https://github.com/miawinter98/just-short-it.git
synced 2024-11-22 00:09:54 +00:00
changed: migrated logout page to razor components
This commit is contained in:
parent
7b2b51f7a2
commit
2247031e11
19
Components/Pages/Logout.razor
Normal file
19
Components/Pages/Logout.razor
Normal 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);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
@page
|
||||
@model JustShortIt.Pages.LogoutModel
|
||||
@{
|
||||
ViewData["Title"] = "Logout";
|
||||
}
|
||||
|
||||
<p class="text-xl text-error">How did you get here?</p>
|
||||
|
|
@ -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("~/");
|
||||
}
|
||||
}
|
|
@ -55,6 +55,7 @@
|
|||
});
|
||||
builder.Services.AddScoped<AuthenticationStateProvider, ServerAuthenticationStateProvider>();
|
||||
builder.Services.AddCascadingAuthenticationState();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
Loading…
Reference in a new issue