0

I have a Blazor server side application with a custom identityprovider. Whenever I need to recover the identity I do so from the session storage using javascript. This all works well. But now I have added an upload control and I have embedded it with <CascadingAuthenticationState> to see if the identity was still known until that point, which it is. Once I try to upload a file it makes a call to a controller using routing and that's where it goes haywire. Once I enter the constructor of the controller the identity is null. All attempts to recover it using javascript result in

JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendered

While I am familiar with this error message, I am puzzled why this happens because the render mode of the application is Server and not ServerPrerendered. Is it because I am in a post event? I've also played with several ways passing the httpcontext but that's also null.

Basically what I'm trying to accomplish is that I need my token there to call an API, but I've lost all track of who I am at that point. I can think of ugly solutions like passing it in the URL, but that's not safe at all. Or store it in a singleton with a lock or something like that, but those are all fugly solutions.

Can anyone kick me into right direction? I feel like I'm running into a very large, very dark forest now.

Ronald.ZaZ
  • 51
  • 1
  • 3
  • Auth tokens should be getting sent in the headers. Inject the context. Here are a couple of links that may help. https://gist.github.com/SteveSandersonMS/175a08dcdccb384a52ba760122cd2eda https://stackoverflow.com/questions/60264657/get-current-user-in-a-blazor-component – Nikki9696 Jan 22 '21 at 19:12
  • @Nikki9696 Yeah, that's how I'd normally do it, but in this case I have no control over the headers. I use an upload component which has a property called "UploadUrl" which is just a string. The component calls that controller on its own. I've tested modifying the upload url by also passing my token and changed the routing on my controller so it supports it, but then the token is in the url. – Ronald.ZaZ Jan 23 '21 at 00:17

1 Answers1

0

The vendor of the component added a new event to add custom headers, so now my problem is solved.

Ronald.ZaZ
  • 51
  • 1
  • 3