0

我是斯巴达克斯的新手。我的问题是针对访客用户的。我需要跳过结帐登录页面并直接重定向到送货地址。而且我还自定义了文件checkoutauthguard.ts,这里的问题是canActivate方法被多次调用。

我需要更改任何其他服务还是需要更改任何后端?

export class ChildCheckoutAuthGuard extends CheckoutAuthGuard implements CanActivate {

    constructor(protected routingService: RoutingService, protected authService: AuthService, protected authRedirectService: AuthRedirectService, protected checkoutConfigService: CheckoutConfigService, protected activeCartService: ActiveCartService, protected userService: UserService, protected globalMessageService: GlobalMessageService, private router: Router) {
        super(routingService, authService, authRedirectService, checkoutConfigService, activeCartService);
    }
    canActivate(): Observable < boolean > {
            return combineLatest([this.authService.getUserToken(),
                    this.activeCartService.getAssignedUser(), this.userService.get(),
                ]).pipe(map(([token, cartUser, user]: [UserToken, User, User]) => {
                            if (!token.access_token) {
                                if (this.activeCartService.isGuestCart()) {
                                    this.routingService.go('/checkout/shipping-address');
                                }
                                if (this.checkoutConfigService.isGuestCheckout()) {
                                    this.router.navigate(['/checkout/shipping-address']);
                                    return false;
                                } else {
                                    this.routingService.go('/checkout/shipping-address');
                                }
                            }
                        }
4

0 回答 0