Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logout not Working (BlazorWebAssemblyStandaloneWithIdentity) #132

Closed
Softwerker04 opened this issue Dec 6, 2023 · 9 comments · Fixed by #136
Closed

Logout not Working (BlazorWebAssemblyStandaloneWithIdentity) #132

Softwerker04 opened this issue Dec 6, 2023 · 9 comments · Fixed by #136
Assignees
Labels
Bug Something isn't working

Comments

@Softwerker04
Copy link

Describe the issue
After register a new user and login the logout is not working. The screen is flickering and the user is not logged out.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new project map with regarding projects (Backend and BlazorWasmAuth)
  2. Set both project as start projects
  3. Register a new user
  4. Login for new user
  5. Try to logout

Expected behavior
User should become logged out

.NET Version
8.0.100


Issue Details

Do not edit this section. It is required for issue processing.

@Softwerker04 Softwerker04 added the Not triaged Awaiting review label Dec 6, 2023
@guardrex
Copy link
Collaborator

guardrex commented Dec 6, 2023

Thanks @Softwerker04 ... I'll take a look. We just performed an update that might have accidentally broken it.

@guardrex
Copy link
Collaborator

guardrex commented Dec 6, 2023

Yep! We broke it! Jeremy is the sample author, and he supplied some code to prevent posting anything but an empty JSON message {}, and that code that he sent over seems to have broken the logout. Stand-by .... if I don't see the resolution, I'll ping him to take a look.

@guardrex
Copy link
Collaborator

guardrex commented Dec 6, 2023

@JeremyLikness ... The logout code that you sent is failing, placing the logout in a nasty loop on the following exception ...

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
Microsoft.AspNetCore.Http.BadHttpRequestException: Expected a supported JSON media type but got "".

@guardrex
Copy link
Collaborator

guardrex commented Dec 6, 2023

@Softwerker04 ... Until Jeremy comes in with a fix, you can change to the prior code. You can see it on the PR diff ......

https://github.com/dotnet/blazor-samples/pull/130/files

@guardrex
Copy link
Collaborator

guardrex commented Dec 6, 2023

Jeremy, the code is ...

app.MapPost("/logout", async (
    SignInManager<AppUser> signInManager,
    [FromBody]object empty) =>
{
    if (empty is not null)
    {
        await signInManager.SignOutAsync();
        return Results.Ok();
    }
    return Results.NotFound();
}).RequireAuthorization();

... and I've temporarily reverted the sample back to the prior code with a note (code comment) to see this issue.

@Softwerker04
Copy link
Author

@guardrex, @JeremyLikness After changing the handler for logout endpoint the mechanism seems to work. Great job, thanks a lot for your support!!!

@PedrooNL
Copy link

PedrooNL commented Dec 7, 2023

@guardrex, @JeremyLikness After changing the handler for logout endpoint the mechanism seems to work. Great job, thanks a lot for your support!!!

@Softwerker04 Can you explain what you did? Having the same issue.

@guardrex
Copy link
Collaborator

guardrex commented Dec 7, 2023

@PedrooNL
Copy link

PedrooNL commented Dec 7, 2023

Revert to the prior code for now ...

https://github.com/dotnet/blazor-samples/blob/main/8.0/BlazorWebAssemblyStandaloneWithIdentity/Backend/Program.cs#L47-L51

Got it. Works. Thanks.

@guardrex guardrex added Bug Something isn't working and removed Not triaged Awaiting review labels Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants