reactjs - 如何从角度应用程序中的反应应用程序接收更新的身份验证令牌
问题描述
我有一个角度应用程序,它与反应应用程序集成并在 UAT 中正常工作。我们面临的唯一问题是,react 为我们提供了一个仅有效一小时的令牌,一小时后过期,但 Angular 应用程序不知道令牌的有效性,我如何检查令牌是否仍然有效或在 Angular 中过期. 如果令牌已过期,那么如何从反应中获取新的有效令牌。
这是从 react 收到的内容:
@Input() data;
@Output() callBackReactComponent: EventEmitter<any> = new EventEmitter<any>();
:
:
:
ngOnInit(): void {
console.log('data from react:');
console.log(this.data);
this.commonService.setToken(this.data);
}
我在我的 api 请求中使用这个令牌:
apollo.create({
link: setContext((_, { headers }) => ({
headers: {
...headers,
authorization: `Bearer ${commonSerivce.getToken()}`
},
})).concat(httpLink.create({ uri: `${baseUrl}/graphql` })),
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: { fetchPolicy: 'network-only', errorPolicy: 'all' },
query: { fetchPolicy: 'no-cache', errorPolicy: 'all' },
},
});
在反应应用程序中,我将角度应用程序渲染为:
<app-root ref={elem => this.nv = elem} data={this.props.token.split(" ")[1]}></app-root>
不涉及按钮或链接单击或表单,如何在不重新加载或刷新的情况下获取新令牌。
提前致谢。
解决方案
推荐阅读
- angular2-routing - call resolver function one more time
- amazon-cognito - Aws amplify federated sign in trough iframe 'X-Frame-Options' to 'deny'
- javascript - 每次运行我的基准代码时(不仅仅是每个周期),如何让 Benchmark.js 进行设置/拆卸?
- python - How to override python pyramid app config settings?
- r - Quantstrat: apply.paramset fails due to combine error for certain paramater distributions, but not others
- sql-server - SQL Server 2008 R2 - How to use a production database through dev/test environments or how to copy a SQL schema and all its data to another
- hyperlink - 我必须在 Dreamweaver 中的某些链接上使用“../”。这是正常的吗?
- pine-script - 如何在策略脚本中修复此错误
- xml - 如何使用 Power BI 中的 API 在 VersionOne 中获取子项目 (Scope.Name) 的开始和结束日期?
- regex - 如果不在数字之间,则正则表达式匹配字符