如何在 NGXS 中的不同选项卡之间同步状态
我在多个选项卡之间的同步状态有问题。这是场景。我有操作REFRESHTOKEN
和刷新tokensucces
刷新用户令牌。 eferything工作正常,直到我用两个浏览器选项卡打开应用程序为止。现在,当令牌已过期时,我正在刷新它在Active选项卡中,但是当我返回第二个标签状态时,请使用旧令牌请求时,发送了将用户删除的。您是否有任何建议将验证数据在第一个标记中刷新后在第二个选项卡中保持最新状态?
@Action(RefreshToken)
public refresh(ctx: StateContext<AuthEntity>): Observable<void | Observable<void>> {
const state = ctx.getState();
return this.authHttpService.refreshToken(state).pipe(
map((data) => ctx.dispatch(new RefreshSuccess(data))),
catchError(() => {
return ctx.dispatch(new Logout());
})
);
}
@Action(RefreshSuccess)
public refreshSuccess(ctx: StateContext<AuthEntity>, action: RefreshSuccess): void {
const state = ctx.getState;
ctx.setState({...state, ...AuthEntity.fromData(action.payload)});
}
I have a problem with synchronize state between multiple tabs. Here is scenario. I have actions RefreshToken
and RefreshTokenSucces
to refresh user token. Eferything is working fine until I open my app in two browser tabs. Now when token is expired and I am refreshing it succesfullly in active tab, but when i returned to the second tab state is outdated and request with old token are send which logoing out the user. Have you any suggestions how to keep auth data up to date in second tab after token is refreshed in first one?
@Action(RefreshToken)
public refresh(ctx: StateContext<AuthEntity>): Observable<void | Observable<void>> {
const state = ctx.getState();
return this.authHttpService.refreshToken(state).pipe(
map((data) => ctx.dispatch(new RefreshSuccess(data))),
catchError(() => {
return ctx.dispatch(new Logout());
})
);
}
@Action(RefreshSuccess)
public refreshSuccess(ctx: StateContext<AuthEntity>, action: RefreshSuccess): void {
const state = ctx.getState;
ctx.setState({...state, ...AuthEntity.fromData(action.payload)});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论