User mapping and connection after a SQL Server restore

I need to restore a database of one SQL Server instance on another and I am aware that the users of the database will be transferred, but not the logins. I created a script to be able to create the connections on the destination SQL Server instance, including the hashed password and the login SID. However, I do not know if it is important to know whether the connections are created on the destination instance before the database is restored or after the database is restored.

If the connections are created first, and then the database is restored, the database users will map the corresponding existing connections because of the security identifier (IDS). need to make an ALTER USER WITH LOGIN or similar?