β I'm trying to allow CORS on C# in order to allow cookies on my frontend, but I fail.
Hey, I'm trying to create a functionality that works this way:
I login-in in the frontend -> The backend receive the username that logged-in with controller http method -> I store the username inside a state and show it to the user on the top-left of the screen.
Now, I added those lines to the Program.cs file:
I don't get CORS message, but the username doesn't pass to the frontend, it gets an empty string.
I added the network status with picture and the flow of my idea.
I really need help, I have a tiny deadline with this project and I need to finish this part, so thanks for whoever helpsπ
And I'm a beginner
, so please communicate with basic language so I can follow!


16 Replies
Does your
/api/auth/login endpoint return a username? Can you show the payload page in the debug tools?
@Yarden
Also, manually overriding the CORS headers in a middleware is... uh.. interesting, but C# has built in support for CORS and I'd probably recommend you use that insteadAs always doesn't get notifications.. sorry
Yes it does kind of
As I figured out in the React discord that I use proxy, so CORS doesn't apply
This is the login: (first pic)
This is the getUser: (second pic)


Inside React I just don't manage to get the value of the username
I'm using states but it doesn't store the value, and I'm trying to figure out the problem but I don't manage

It seems like I can't store the value from the http get call
Hopefully I gave the info you asked for.
And I looked at discord 1 hour after the creation of the post and saw no answer, something it totally broken with my discord
Response.Data will not just be the string btw
Its an object with a username prop
Yeah I know, I tried everything...
I tried to get the value it self by data.username but once I update the state with it, it disappears
I don't manage to find the problem
I manage to print the username which is : yaryaryar
But once I update the state with setUsernameLabel and tried to print: usernameLabel it prints nothing.
Pretty redicilous

so your issue is with the react code then
^ I think so too
Yep
When I created this post I didn't know where the problem is, but now it seems like react.
It seems like I managed to store the value inside the state, but now I have other problems as always.
I will check it out
Thank you a lot for the help
I appriciate that
Without knowing react at all, I somehow managed to make this all work
When I say I, I mean claude π
Have a good one guys π
Absolutely not sure this is the way to go, but it created an
AuthProvider that wrapped the Outlet component(?), created an authcontext that handles the login/logout and updating of the user state, two components: loginform and logout button...
accessing the user seems very straight forward at least π