Set redirect path after customer account login

After logging in a user, I would like to redirect them to the last visited store page. I am using the Customer Account API’s (2024-10) login() method. The docs state a return_to parameter is being automatically set unless customAuthStatusHandler is used, which I am not.

So for example, if a user happens to be on a product page and hits the login button in the navbar, I would like to pass the pathname of this current product page to the login function, so when the user is logged in, they get redirected to the page they were before.

As it is right now when using the auth routes setup from the skeleton template, the user gets redirected to the /account route. This is suboptimal user experience.

Is there any way to set the redirect path?

Any authenticated account route needs to call await context.customerAccount.handleAuthStatus(); inside the loader. Or you could do it in a wildcard route like in our starter template

Yes, I’m actually using the auth routes setup from the skeleton template.
I’m going to add an example to my question to make it clearer what my goal is.