> most auth providers are very expensive
Some are, sure, but there are many that are not.
FusionAuth (again, I'm an employee) has a free community edition ( https://fusionauth.io/pricing?step=plan&hosting=self-hosting ) if you run it yourself with no limits on MAUs, SAML connections, tenants or users. Of course, we have plans that cost money because, hey, we all like to eat.
Auth0 has a basic plan that is free for 7k users. Mostly focuses on username and password, but is entirely adequate for getting started.
Ory (suggested elsewhere in the thread and by you) is OSS and free. Again, you have to operate it, which isn't free, but you get the benefits of upgrades and a team focused on auth.
Keycloak has a lot of features and is free if your run it yourself.
Supertokens has a basic plan that is free for 5k users.
There are many more, as well. And that is to say nothing of the OSS libraries (like devise/omniauth) which you can leverage.
Coding this from scratch seems like an enormous waste of time for something that is not typically a differentiator. At the least, use an OSS library or auth service and limit yourself to the features you need.
Customers pay for features, not for auth. Auth is just the front door to the application.