Looking at the source and docs of some of the methods involved in this process, I think you store somewhere in the session that the user is using the mobile version. Before signing in, you wipe out the existing session with sign_out_all_scopes
then you go ahead with the login, but the session has been wiped so by the time the redirect URL is generated it doesn't know that it should be for the mobile version.
—
This should probably be a comment instead of an answer, but I don't have enough reputation for that yet.