我需要创建效果,它将在时间间隔内使用 refresh-token 刷新访问令牌
I need to create effect which will in time intervals refresh access token with refresh-token
我想创建在用户成功登录后按时间间隔刷新令牌的效果,我还需要 select 来自商店的 refreshToken,这对我来说开始太复杂了,我想不通弄清楚怎么做。
到目前为止的效果
@Effect()
refreshAccessToken$ =
this.actions$.pipe(
ofType(AccountActionsTypes.AccountLoginSuccess),
map(() => {
interval(5000)
.pipe(
mapTo(() => this.store
.pipe(
select(selectRefreshToken),
map(refreshToken => {
if (refreshToken != '' && refreshToken != undefined) {
this.accountService.refreshToken(refreshToken)
.pipe(
map((response: { token: string }) => {
return {type: AccountActionsTypes.RefreshTokenSuccess, token: response.token};
})
);
} else {
return {type: AccountActionsTypes.RefreshTokenSuccess, token: ''};
}
})
)));
}));
但是我得到这个错误
也许有人会觉得这有帮助,这是建议修复的效果:
@Effect()
refreshAccessToken$ =
this.actions$.pipe(
ofType(AccountActionsTypes.AccountLoginSuccess),
switchMap(() => {
return interval(5000)
.pipe(
switchMap(() => this.store
.pipe(
select(selectRefreshToken),
switchMap((refreshToken) => this.accountService.refreshToken(refreshToken)
.pipe(
map((response: { token: string, status: string }) => {
if (response.token !== undefined) {
return {
type: AccountActionsTypes.RefreshTokenSuccess,
token: response.token,
};
} else {
return {type: AccountActionsTypes.RefreshTokenWrong, status: response.status};
}
})
))
)));
}));
如果你想 return 一个内部可观察对象,你必须使用展平运算符:
@Effect()
refreshAccessToken$ =
this.actions$.pipe(
ofType(AccountActionsTypes.AccountLoginSuccess),
//
switchMap(() => { ... })
我想创建在用户成功登录后按时间间隔刷新令牌的效果,我还需要 select 来自商店的 refreshToken,这对我来说开始太复杂了,我想不通弄清楚怎么做。
到目前为止的效果
@Effect()
refreshAccessToken$ =
this.actions$.pipe(
ofType(AccountActionsTypes.AccountLoginSuccess),
map(() => {
interval(5000)
.pipe(
mapTo(() => this.store
.pipe(
select(selectRefreshToken),
map(refreshToken => {
if (refreshToken != '' && refreshToken != undefined) {
this.accountService.refreshToken(refreshToken)
.pipe(
map((response: { token: string }) => {
return {type: AccountActionsTypes.RefreshTokenSuccess, token: response.token};
})
);
} else {
return {type: AccountActionsTypes.RefreshTokenSuccess, token: ''};
}
})
)));
}));
但是我得到这个错误
也许有人会觉得这有帮助,这是建议修复的效果:
@Effect()
refreshAccessToken$ =
this.actions$.pipe(
ofType(AccountActionsTypes.AccountLoginSuccess),
switchMap(() => {
return interval(5000)
.pipe(
switchMap(() => this.store
.pipe(
select(selectRefreshToken),
switchMap((refreshToken) => this.accountService.refreshToken(refreshToken)
.pipe(
map((response: { token: string, status: string }) => {
if (response.token !== undefined) {
return {
type: AccountActionsTypes.RefreshTokenSuccess,
token: response.token,
};
} else {
return {type: AccountActionsTypes.RefreshTokenWrong, status: response.status};
}
})
))
)));
}));
如果你想 return 一个内部可观察对象,你必须使用展平运算符:
@Effect()
refreshAccessToken$ =
this.actions$.pipe(
ofType(AccountActionsTypes.AccountLoginSuccess),
//
switchMap(() => { ... })