Redirect in onExecutePostLogin interrupts device flow

Hi,

we would like to redirect users to a custom page after successfully completing the device flow. When implementing this in an action in the onExecutePostLogin, the redirect seems to happen before the actual device code validation. The code is never validated and the “/oauth/token” request with the device_code never completes successfully.

The action looks like this:

exports.onExecutePostLogin = async (event, api) => {
  
  if(event.transaction && event.transaction.protocol === "oauth2-device-code"){
    console.log("device flow");
    
    api.redirect.sendUserTo("https://....."); 
  }else{
    console.log("NOT device flow");
  }
};

The action is hit twice during the device flow, the first time the condition is false, the second time (after confirming the device code) the condition is true. The redirect happens, but the flow is interrupted anyway.
How can we redirect users without interrupting the device code flow?