微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ASPNetCore 用户注销 NotAuthorized 组件未显示退出后无法登录瓦斯姆

如何解决ASPNetCore 用户注销 NotAuthorized 组件未显示退出后无法登录瓦斯姆

列出了解决方案,但不确定是否是最佳实践。

我有一个基于 JWT 身份验证和授权视图的用户登录注销的 WASM aspnetCore 应用程序。用户注销时会发生以下情况。

用户被传递到登录页面。不是主页。然后当用户导航到主页时,没有选项可以查看来自未授权组件的登录信息。

<NotAuthorized>
        <div class="ContainerHeader">
            <span>
                <button type="button" class="HeaderButtons" @onclick="@Register">Sell Your Art With Us!</button>
                <button type="button" class="HeaderButtons" @onclick="@Login">Login</button>
            </span>
        </div>
    </NotAuthorized>

我检查了应用程序的缓存,它按预期运行,在注销后丢弃用户身份验证令牌。所以授权组件应该可以正常工作。

  public async Task logout()
        {
            //Remove the AuthToken of the user. 
            await _localStorage.RemoveItemAsync(key: _siteSettings.AuthTokenStorageKey); //remove the stored token this is neater than just removing all material as you can hold cart items 
            ((AuthStateProvider)_authStateProvider).NotifyUserlogout();
            _client.DefaultRequestHeaders.Authorization = null; // removes access authorization to areas of the API. 
            _navManager.Navigateto("/",forceLoad: true);

        }

我设法解决了这个问题,但它有点笨拙。当用户注销时,我强制加载主页。这会导致页面用户注销后刷新,现在可以看到登录信息。然而,当没有力负载时。下面的代码。未出现登录选项。

            _navManager.Navigateto("/",forceLoad: true);

有谁知道为什么会发生这种情况。有更好的修复建议。如果不是在 至少我希望这有助于解决其他一些问题。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。