Ionic 4 Angular 8 handle server side user redirection

My express server is redirecting the user to an angular page after payment success. Like below

res.redirect('http://localhost:8100/order-success')

I have jwt auth in my app. So if the user is logged in then I redirect the user to url tabs/tab1 else redirects to the login page.

So when my express server redirects the user to order-success page, the logic in jwt auth takes over and the user gets redirected to tabs/tab1 page. But I want the user to be redirected to order-success page. What is the solution?

Thank you in advance

Here is code

authentication.service.ts

export class AuthenticationService {

  authenticationState = new BehaviorSubject(false);

  constructor(private storageservice: StorageService, private plt: Platform, private router: Router) {

    this.plt.ready().then(() => {
      this.checkToken();
    });
   }

   checkToken() {
    this.storageservice.get('token').then(res => {
      if (res) {
        this.authenticationState.next(true);
      }
    })
  }

  login(val) {

    console.log("login")
    return this.storageservice.set('token', val).then(() => {
      this.authenticationState.next(true);
    });
  }
 
  logout() {
    return this.storageservice.clear().then(() => {
      this.authenticationState.next(false);

      let navigationExtras : NavigationExtras = {
        state : {
          logout : "yes"
        }
      }
      this.router.navigate(['home'], navigationExtras)

    });
  }
 
  isAuthenticated() {
    return this.authenticationState.value;
  }

}

app.component.ts

this.authenticationService.authenticationState.subscribe(state => {
    if (state) {         

      console.log(state) // state is true
      this.router.navigate(['tabs/tab1']);
    } 
    else {

      console.log(state) // state is false
      this.router.navigate(['home']);
    }
  });

I think you should just return the status of success from your express app and redirect accordingly in the app. Design wise the express app is tightly coupled with the mobile app.
The app should handle its own concerns and vise versa for the express app.

export class MakePaymentService{
   .......
   makePayment(){
        send http request express app to complete payment...
        get response from request and 
        return result
    }
export class CheckoutPage{
    checkout(){
        this.makepayService.makePayment()
           .subscribe( (response)=>{
               // Evaluate response results here and decide if to go to success page or where else
           });
    }
}

No, actually I can’t do that. The scenario is payment gateway post sensitive data like payment id and order id to my server and then I have to take care of user redirection.

The solution still applies, the key thing is the status message sent to the app from your server since the payment gateway will tell you if the the payment succeeded or not, then relay relay the same as per your needs…
Think of it like http status 200, 201, 301, 404 et al. This code already convey a certain message when received.

What you receive from the gateway helps you determines the status of the payment and what you should and can do. This should be so for the app, if it gets success, pending, failed, canceled etc and respond accordingly… what if the mobile app was to be redesigned, your express app only needs to care it sends the right status, not what the location the app goes to and its up to the app to decide what to do.

Sorry but I am not getting you. Let me show you express code. The payment gateway has sent some data to URL payment-check.
The total scenario - we make a request to the payment gateway, The payment gateway sends some data to payment-check. Now how can I send status code to our client as connection is broken between client and our server?

router.post('/payment-check', function (req, res) {

    var options = req.body // req.body from payment gateway
    console.log(options)
    /payment verification through generating signature
    if (payment is successful) {

        const query = querystring.stringify({
            "valid": options.payment_id,
            "exact": options.order_id
        });

        res.redirect('http://192.168.43.147:8100/order-success/?' + query)

    }

    else {
        console.log("not matched")
        console.log('error')
    }

})

Ideally the connection is not broken since you initiate a HTTP call from the app which will wait for the reply via an observable stream. In-case the user goes offline after the call is made a push notification to the app will notify them of the status of the request they’d made.