AuthorizeView with SessionStorageService error JavaScript interop calls cannot be issued at this time

Chiến Đặng 0 Reputation points
2024-08-01T18:30:09.4733333+00:00

hi,

currently i am getting this error: JavaScript interop calls cannot be issued at this time when get token from SessionStorageService (AuthorizeView ) in blazor sever net8, how can i fix?

when i leave it this : <component type="typeof(App)" render-mode="ServerPrerendered" />

in host.cshml then it ok, but UI nothing.

Can you help me?

@inherits LayoutComponentBase

@inject IJSRuntime JsRuntime

@using BlazorApp.Pages.Authentication

@inject AuthenticationStateProvider AuthenticationStateProvider

@inject IHttpContextAccessor HttpContextAccessor

@inject Blazored.SessionStorage.ISessionStorageService sessionStorage

<AuthorizeView>

<Authorized>

    <div class="bg-[#f9fbfd] dark:bg-dark text-black">

        <div class="bg-[url('assets/images/bg-main.png')] bg-black min-h-[220px] sm:min-h-[250px] bg-bottom fixed hidden w-full -z-50 detached-img"></div>

        <div x-cloak class="fixed inset-0 bg-black/60 dark:bg-dark/90 z-[999] lg:hidden" :class="{'hidden' : !$store.app.sidebar}" @click="ToggleSidebar">

        </div>

        <div class="flex mx-auto main-container">

            <Sidebar></Sidebar>

            <div class="flex-1 main-content">

                <Topbar></Topbar>

                <div class="h-[calc(100vh-60px)]  relative overflow-y-auto overflow-x-hidden p-4 space-y-4 detached-content">

                    @Body

                    <Footer></Footer>

                </div>

            </div>

        </div>

    </div>

</Authorized>

<NotAuthorized>

    <RedirectToLogin />

</NotAuthorized>

</AuthorizeView>

<button type="button" class="fixed z-50 px-4 text-white border-gray-200 shadow-lg h-11 ltr:right-0 rtl:left-0 bg-purple ltr:rounded-l-md rtl:rounded-r-md top-1/3" @onclick="ToggleDirection">

@if (direction == "ltr")

{

    <span>LTR</span>

}

else

{

    <span>RTL</span>

}

</button>

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,584 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.