Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How do I logout in Blazor 8 SSR

$
0
0

I login to the program using the following code:

var ctx = await dbFactory.CreateDbContextAsync();var entForUpdate = ctx.Personels.FirstOrDefault(q => q.Email== model.Email);if (entForUpdate != null) {  Claim rolClaime = default;  Claim Fullname = default;  if (entForUpdate.IDRole == 3) { rolClaime = new Claim(ClaimTypes.Role,      "RoleUser"); } Fullname = new Claim("User", entForUpdate.Email.ToString());  ClaimsIdentity claimsIdentity = new ClaimsIdentity(new[] { rolClaime, Fullname },    "CookieUser"); ClaimsPrincipal User = new ClaimsPrincipal(claimsIdentity); if (entForUpdate.IDRole == 3) { HttpContext.Response.Redirect("/Showuser"); }      }

The top part works fine.

But

Now to logout the program

No matter how hard I try, I can't delete the saved cookie.

private async Task DeleteCookie(){   await JSRuntime.InvokeVoidAsync("deleteCookie");   NavigationManager.NavigateTo("/", true);   `your text`}

js

 function deleteCookie() {     res.cookie("CookieUser", "", { expires: new Date(0), path: '/' });    //or======    document.cookie = CookieUser +'=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>