prodijay
Unable to get logged in user when using React SPA
By the way did you have that in mind when you read through my problem? Did you know that there was an issue with my cookies? I seriously doubt I would have found this solution on my own, and I don't think the docs would necessarily help in this situation either.
18 replies
Unable to get logged in user when using React SPA
I think I managed to fix it! I think it was due to an error with my cookie; the
SameSite
property was set to lax
, which works for when testing with Swagger, but not with React because SameSite
needs to be set to none
when working with cross-site responses. Specifically configuring the cookie policy such that SameSite=none
and Secure=true
allowed me to get the logged in user in the corresponding backend controller action.
Thank you for pointing me in that direction. If you hadn't told me to check the cookie again I would have missed the detail about SameSite
needing to be none
.18 replies
Unable to get logged in user when using React SPA
I've read through the ASPNET Core Identity docs a few times already: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-8.0&tabs=visual-studio
Is there something specifically I should be looking for?
I've added the
useCookies
and useSessionCookies
query strings to the login request because of that, but that still didn't solve my issue of not getting the logged in user.18 replies
Unable to get logged in user when using React SPA
StudyController.cs (https://github.com/jasonHYLam/csharp-test/blob/main/Controllers/StudyController.cs)
Do
HttpContext.User
and _userManager
work differently when using a SPA?
Thank you!18 replies
Unable to get logged in user with GetUserAsync
So what I think happened by changing all instances of
<IdentityUser>
to <User>
is that IdentityDbContext<IdentityUser>
is now IdentityDbContext<User>
, such that it aligns with UserManager<User> userManager
? And previously they were not aligned?39 replies
Unable to get logged in user with GetUserAsync
https://discord.com/channels/143867839282020352/156079822454390784/1253850896941711454
Last night I described how I may be be doing something wrong with my User and IdentityUser types, because I seem to be interchanging them throughout my project, which I wasn't sure if it was a problem or not.
39 replies
Unable to get logged in user with GetUserAsync
The salient files should be
Program.cs
, Model/ApplicationDBContext.cs
, Model/User.cs
, Controllers/StudyController.cs
The studyController is definitely a mess because I was trying so many different ways to get the logged in user.39 replies
Unable to get logged in user with GetUserAsync
https://github.com/jasonHYLam/csharp-test
Okay here it is.
39 replies