prodijay
prodijay
CC#
Created by prodijay on 7/2/2024 in #help
✅ Azure app service Web API project not running
Please ignore this post for the time being. For some reason, I am able to access the deployed Web API from my deployed React frontend.
4 replies
CC#
Created by prodijay on 6/26/2024 in #help
What return method is appropriate for controller actions for SPA frontend?
Great I think this is what I needed, thank you!
3 replies
CC#
Created by prodijay on 6/24/2024 in #help
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
CC#
Created by prodijay on 6/24/2024 in #help
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
CC#
Created by prodijay on 6/24/2024 in #help
Unable to get logged in user when using React SPA
Actually I notice the yellow warning symbol, let me investigate that. It's complaining about the sameSite=lax not agreeing with the cross site response.
18 replies
CC#
Created by prodijay on 6/24/2024 in #help
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
CC#
Created by prodijay on 6/24/2024 in #help
Unable to get logged in user when using React SPA
No description
18 replies
CC#
Created by prodijay on 6/24/2024 in #help
Unable to get logged in user when using React SPA
No description
18 replies
CC#
Created by prodijay on 6/24/2024 in #help
Unable to get logged in user when using React SPA
StudyController.cs (https://github.com/jasonHYLam/csharp-test/blob/main/Controllers/StudyController.cs)
c#
[ApiController]
[Route("[controller]")]
public class StudyController : ControllerBase
{
private readonly Cloudinary _cloudinary;
private readonly UserManager<User> _userManager;
private readonly ApplicationDbContext _context;

public StudyController(
ApplicationDbContext context,
UserManager<User> userManager,
Cloudinary cloudinary
)
{
_context = context;
_userManager = userManager;
_cloudinary = cloudinary;
}

\\ ...

[HttpGet("allStudies")]
public async Task<ActionResult<IEnumerable<StudyPreviewDTO>>> GetAllStudies()
{

var user = await _userManager.GetUserAsync(HttpContext.User);
Console.WriteLine("checking user");
Console.WriteLine(HttpContext.User); // returns null
c#
[ApiController]
[Route("[controller]")]
public class StudyController : ControllerBase
{
private readonly Cloudinary _cloudinary;
private readonly UserManager<User> _userManager;
private readonly ApplicationDbContext _context;

public StudyController(
ApplicationDbContext context,
UserManager<User> userManager,
Cloudinary cloudinary
)
{
_context = context;
_userManager = userManager;
_cloudinary = cloudinary;
}

\\ ...

[HttpGet("allStudies")]
public async Task<ActionResult<IEnumerable<StudyPreviewDTO>>> GetAllStudies()
{

var user = await _userManager.GetUserAsync(HttpContext.User);
Console.WriteLine("checking user");
Console.WriteLine(HttpContext.User); // returns null
Do HttpContext.User and _userManager work differently when using a SPA? Thank you!
18 replies
CC#
Created by prodijay on 6/21/2024 in #help
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
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
Okay for SOME REASON that resolved me being able to get the logged in user.
39 replies
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
Okay I've just resolved the User/IdentityUser interchanging situation. So I set User where all instances of type IdentityUser used to be. I'll see how that affects _userManager.GetUserAsync().
39 replies
CC#
Created by prodijay on 6/21/2024 in #help
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
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
The _userManager can be found on line 14 in StudyController. However I'm not using it anywhere else in the project.
39 replies
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
Oh and for more context, I am using this with a React SPA. Please ignore the Pages directory.
39 replies
CC#
Created by prodijay on 6/21/2024 in #help
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
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
39 replies
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
Thanks for being patient yall😙
39 replies
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
I get that, yeah
39 replies
CC#
Created by prodijay on 6/21/2024 in #help
Unable to get logged in user with GetUserAsync
Hi, I'll share my repo in a little bit, I just need to figure out how to hide my connection string when I push to GitHub.
39 replies