问题描述
列出了解决方案,但不确定是否是最佳实践。
我有一个基于 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 (将#修改为@)