3 ms·
Ant & I are excited to release Supabase Auth. Supabase is an open source Firebase alternative. We are building the features of Firebase using scalable, open sou
by kiwicopple 6y ago
Ant & 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.
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:
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.
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.
AuthN+AuthZ: when a user signs up to your app/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.
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.
Note - we’re still in alpha! Please be lenient :). There are some missing features (we’ll be enabling email confirmations/password reset in 1 or 2 weeks)
[1] Previous Launch: https://news.ycombinator.com/item?id=23319901 https://news.ycombinator.com/item?id=23319901
[2] RLS: https://www.postgresql.org/docs/current/ddl-rowsecurity.html https://www.postgresql.org/docs/current/ddl-rowsecurity.html
[3] PostgREST auth: http://postgrest.org/en/v7.0.0/auth.html http://postgrest.org/en/v7.0.0/auth.html
[4] Policies: https://www.postgresql.org/docs/current/sql-createpolicy.html https://www.postgresql.org/docs/current/sql-createpolicy.htm...
[5] Social network: https://github.com/steve-chavez/socnet/blob/f1abaadaaedb7c8e9a9a57fbe3a555fb767a5266/security/users.sql#L65-L80 https://github.com/steve-chavez/socnet/blob/f1abaadaaedb7c8e...
[6] GoTrue: https://github.com/netlify/gotrue https://github.com/netlify/gotrue
- an_opabinia 6y agoIt looks like your client takes a URL that points to your domain. Is there open source code that runs that URL? In other words, did you open source the part of the application the client connects to?
- kiwicopple 6y agoAt the moment no: https://supabase.io/docs/faq#how-do-i-host-supabase https://supabase.io/docs/faq#how-do-i-host-supabase When we get out of alpha, we will release a fat middleware server which stitches together the the open source tools we are using. Firebase isn't just "one thing", which will make it increasingly difficult to pack into a single server as we grow, so it might end up being several servers split up by feature. Here are all the tools we use: https://supabase.io/docs/#how-it-works https://supabase.io/docs/#how-it-works
- nicoburns 6y agoSupabase is pretty exciting. Our product at work was initially hosted on Firebase, and while there were some really nice aspects to it (auth, realtime querying) we had a whole host of problems with the limited querying power of Firebase's non-relational model. So we've gradually been porting everything over to Postgres (with Hasura for realtime queries). I have a question about the new auth functionality: In the blog post it shows configuring auth rules via a GUI. Is there also support for a code-first approach where these rules are stored in a (sanely human editable) text format, which is then synced up to the server via a CLI or similar. I've found that this is absolutely crucial in order to ensure consistency between dev and prod environments, and to be able to spin up testing environments. For that matter, is there an easy way to run the superbase stack locally as a local dev environment?
- kiwicopple 6y ago> Is there also support for a code-first approach We plan to build git integrations which will handle migrations (including Policies) and two-way syncing between git and postgres. For now, you'd have to handle this yourself (we give you root access to your Postgres database) > is there an easy way to run the superbase stack locally We had(have) a docker image but it's outdated. We're in the process of updating for local development. It handles the middleware, but not the UI (for now)