Auth is now available in Supabase (YC S20)
Ant &amp; I are excited to release Supabase Auth. Supabase is an open source Firebase alternative. We are building the features of Firebase using scalable, open source products. Back in May one of our users unexpectedly launched us on Hacker News[1]. There were a lot of comments about Auth: many people asking for it, and many wondering how we would implement it.<p>If you don’t care for the details, the linked blog post is more high-level. For anyone interested in the technical details, this is how we implemented our Auth system from the bottom up:<p>Authorization: Supabase is built with Postgres + PostgREST so we were adamant that we’d use PostgreSQL’s row level security[2] for authorization.  PostgREST solves most of the hard work with their auth system[3] and Supabase hides the PostgREST implementation when you start a new project. We create a few roles in your database: one “anon” role which is restricted, and one “authenticated” role which users can “assume” once they are logged in. Inside your database, you can then add Postgres Policies[4]. These are incredibly powerful (see Steve’s “social network” database[5]). Admittedly they can be confusing, but we have plans to make them simple. Their flexibility outweighs their complexity in any case.<p>Authentication: After trying many open source tools, we found Netlify’s GoTrue[6]. This was simple and covered most of the functionality we need. There are some missing Oauth clients, so we will contribute them when we roll out Oauth (we only have email login for now). When a user starts a new Supabase project, we create an “auth” schema in their database. GoTrue stores the users and user data in this schema.<p>AuthN+AuthZ: when a user signs up to your app&#x2F;project, GoTrue assigns them a unique UID, saves them in the auth schema, and returns a JWT with the user’s details. Our client library attached this JWT to every API request. PostgREST validates the JWT then sends the request through to Postgres. Postgres is able to inspect the request header to get the user’s role and UID, but to make this easy we added some helper functions to the auth schema: one to get the logged in user’s UID (`auth.uid()`) and one to get the logged in user’s role (`auth.role()`). These functions can be used in the Postgres Policies to create a very powerful rules engine.<p>Postgres is one of those tools which you love the more you use it. RLS+Policies are no exception here. It’s very cool being able to specify rules in your database and then be carefree in your frontend. We hope you’ll try it out and send feedback.<p>Note - we’re still in alpha! Please be lenient :). There are some missing features (we’ll be enabling email confirmations&#x2F;password reset in 1 or 2 weeks)<p>[1] Previous Launch: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23319901" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=23319901</a><p>[2] RLS: <a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;ddl-rowsecurity.html" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;ddl-rowsecurity.html</a><p>[3] PostgREST auth: <a href="http:&#x2F;&#x2F;postgrest.org&#x2F;en&#x2F;v7.0.0&#x2F;auth.html" rel="nofollow">http:&#x2F;&#x2F;postgrest.org&#x2F;en&#x2F;v7.0.0&#x2F;auth.html</a><p>[4] Policies: <a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;sql-createpolicy.html" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;sql-createpolicy.htm...</a><p>[5] Social network: <a href="https:&#x2F;&#x2F;github.com&#x2F;steve-chavez&#x2F;socnet&#x2F;blob&#x2F;f1abaadaaedb7c8e9a9a57fbe3a555fb767a5266&#x2F;security&#x2F;users.sql#L65-L80" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;steve-chavez&#x2F;socnet&#x2F;blob&#x2F;f1abaadaaedb7c8e...</a><p>[6] GoTrue: <a href="https:&#x2F;&#x2F;github.com&#x2F;netlify&#x2F;gotrue" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;netlify&#x2F;gotrue</a>