Post Login Flow Action is executing pre-login

I’m looking to create the following flow in my app using actions:

  1. The user logs in, either using Google sign-in or by providing username and password.
  2. I want an action to check if there is a given_name field on the user (there will be if done with Google, there won’t if done with username and password (I think)).
  3. If there is no given_name I want to redirect my user to my application where they can fill in those details. I’ll then use the Management API to update the user, and then use /continue to redirect back to the flow.

My action looks like this currently:

exports.onExecutePostLogin = async (event, api) => {
  if (event.user && !(event.user.given_name) || !(event.user.family_name)){
    api.redirect.sendUserTo('my-url/new-user')
  }
};

The problem I’m having is that this is executing before the user gets to the Universal login page - so before any logging in is actually happening. Is this expected behaviour? How can I get the action to not execute until after the user has actually entered their details?

Hi there @raph90!

It’s definitely not expected behavior that this fires before login - What makes you think this is the case?

Let us know and we can go from there!