Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add learn dir

Terry Sutton6ea0aad5509a
diff --git a/apps/temp-docs/docs/learn/auth-deep-dive/google-oauth.md b/apps/temp-docs/docs/learn/auth-deep-dive/google-oauth.md
new file mode 100644
index 00000000000..129ce770fd2
--- /dev/null
+++ b/apps/temp-docs/docs/learn/auth-deep-dive/google-oauth.md
@@ -0,0 +1,92 @@
+---
+id: auth-google-oauth
+title: 'Part Five: Google Oauth'
+description: 'Supabase Deep Dive Part 5: Google OAuth Provider'
+---
+
+### About
+
+How to add Google OAuth Logins to your Supabase Application.
+
+### Watch
+
+<div class="video-container">
+<iframe src="https://www.youtube-nocookie.com/embed/_XM9ziOzWk4" frameBorder="1" allow="accelerometer;autoplay; clipboard-write encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
+</div>
+
+### Logging in with external OAuth providers
+
+Connecting social logins such as Google, GitHub, or Facebook couldn't be easier. In this guide we'll walk you through the process of connecting Google, but the process is basically the same for all of the providers which includes: azure, bitbucket, github, gitlab, facebook, and google.
+
+First you'll need to create a google project inside their [cloud console](https://console.cloud.google.com/home/dashboard), in other providers they may refer to this as an "app" and is usually available on the company's developer portal.
+
+![Create a new Google Project inside cloud console](/img/auth-5-1.png)
+
+Once you have a project, type "OAuth" into the search bar and open up "OAuth Consent Screen"
+
+![Open the OAuth consent screen](/img/auth-5-2.png)
+
+Select 'External' and proceed to fill out the rest of the form fields
+
+![Select External on the OAuth form](/img/auth-5-3.png)
+
+Next open up Credentials page on the left
+
+![Open up Credentials page](/img/auth-5-4.png)
+
+And click to create a new set of credentials, select OAuth client ID as the option
+
+![Create new oauth client id credentials](/img/auth-5-5.png)
+
+Now choose Web Application (assuming you're creating a web app) and in the Authorized redirect URI section you need to add: `https://<your-ref>.supabase.co/auth/v1/callback`. You can find your Supabase URL in Settings > API inside the Supabase dashboard.
+
+![Add your redirect URI](/img/auth-5-6.png)
+
+Now you can grab the client ID and secret from the popup, and insert them into the google section inside the Supabase dashboard in Auth > Settings:
+
+![take client id and secret](/img/auth-5-7.png)
+
+![insert client id and secret into supabase dashboard in auth > auth](/img/auth-5-8.png)
+
+Hit save. Now you should be able to navigate in the browser to:
+
+```
+https://<your-ref>.supabase.co/auth/v1/authorize?provider=google
+```
+
+And log in to your service using any google or gmail account.
+
+You can additionally add a query parameter `redirect_to=` to the end of the URL for example:
+
+```
+https://<your-ref>.supabase.co/auth/v1/authorize?provider=google&redirect_to=http://localhost:3000/welcome
+```
+
+But make sure any URL you enter here is on the same host as the site url that you have entered on the Auth > Settings page on the Supabase dashboard. (There is additional functionality coming soon, where you'll be able to add additional URLs to the allow list).
+
+If you want to redirect the user to a specific page in your website or app after a successful authentication.
+
+You also have the option of requesting additional scopes from the oauth provider. Let's say for example you want the ability to send emails on behalf of the user's gmail account. You can do this by adding the query parameter `scopes`, like:
+
+```
+https://<your-ref>.supabase.co/auth/v1/authorize?provider=google&https://www.googleapis.com/auth/gmail.send
+```
+
+Note however that your app will usually have to be verified by Google before you can request advanced scopes such as this.
+
+The only thing left to implement is the UI, but if you prefer to use something pre-built, we have a handy [Auth Widget](https://github.com/supabase/ui/#using-supabase-ui-auth), where you can enable/disable whichever auth providers you want to support.
+
+For any support please get in touch at beta at [supabase.com](https://supabase.com) or for feature requests open an issue in the [backend](https://github.com/supabase/gotrue) or [frontend](https://github.com/supabase/gotrue-js) repos.
+
+### Resources
+
+- [JWT debugger](https://jwt.io)
+
+### Next steps
+
+- Watch [Part One: JWTs](../../learn/auth-deep-dive/auth-deep-dive-jwts)
+- Watch [Part Two: Row Level Security](../../learn/auth-deep-dive/auth-row-level-security)
+- Watch [Part Three: Policies](../../learn/auth-deep-dive/auth-policies)
+- Watch [Part Four: GoTrue](../../learn/auth-deep-dive/auth-gotrue)
+<!-- - Watch [Part Five: Google Oauth](../../learn/auth-deep-dive/auth-google-oauth) -->
+- Sign up for Supabase: [app.supabase.com](https://app.supabase.com)
diff --git a/apps/temp-docs/docs/learn/auth-deep-dive/gotrue.md b/apps/temp-docs/docs/learn/auth-deep-dive/gotrue.md
new file mode 100644
index 00000000000..3b780f254fd
--- /dev/null
+++ b/apps/temp-docs/docs/learn/auth-deep-dive/gotrue.md
@@ -0,0 +1,74 @@
+---
+id: auth-gotrue
+title: 'Part Four: GoTrue'
+description: 'Supabase Deep Dive Part 4: Gotrue Overview'
+---
+
+### About
+
+How to restrict table access to authenticated users, row level policies, and email domain based access.
+
+### Watch
+
+<div class="video-container">
+<iframe src="https://www.youtube.com/embed/neqfYym_84k" frameBorder="1" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
+</div>
+
+### Gotrue Server
+
+Gotrue is an auth API server written in Go by the Netlify team, find the Supabase fork here: https://github.com/supabase/gotrue. The list of available API endpoints is available [here](https://github.com/supabase/gotrue#endpoints).
+
+When you deploy a new Supabase project, we deploy a new instance of this server alongside your database, and also inject your database with the required `auth` schema.
+
+It makes it super easy to, for example, send magic link emails which your users can use to login:
+
+```bash
+# replace <project-ref> with your own project reference
+# and SUPABASE_KEY with your anon api key
+curl -X POST 'https://<project-ref>.supabase.co/auth/v1/magiclink' \
+-H "apikey: SUPABASE_KEY" \
+-H "Content-Type: application/json" \
+-d '{
+ "email": "[email protected]"
+}'
+```
+
+Gotrue is responsible for issuing access tokens for your users, sends confirmation, magic-link, and password recovery emails (by default we send these from a Supabase SMTP server, but you can easily plug in your own inside the dashboard at Auth > Settings) and also transacting with third party OAuth providers to get basic user data.
+
+The community even recently built in the functionality to request custom OAuth scopes, if your users need to interact more closely with the provider. See the scopes parameter here: [https://github.com/supabase/gotrue#get-authorize](https://github.com/supabase/gotrue#get-authorize).
+
+So let's say you want to send emails on behalf of a user via gmail, you might request the gmail.send scope by directing them to:
+
+```
+https://sjvwsaokcugktsdaxxze.supabase.co/auth/v1/authorize?provider=google&https://www.googleapis.com/auth/gmail.send
+```
+
+You'll have to make sure your google app is verified of course in order to request these advanced scopes.
+
+[Gotrue-js](https://github.com/supabase/gotrue-js) (and also [gotrue-csharp](https://github.com/supabase/gotrue-csharp), [gotrue-py](https://github.com/j0/gotrue-py), [gotrue-kt](https://github.com/supabase/gotrue-kt), and [gotrue-dart](https://github.com/supabase/gotrue-dart)) are all wrappers around the gotrue API endpoints, and make for easier session management inside your client.
+
+But all the functionality of gotrue-js is also available in supabase-js, which uses gotrue-js internally when you do things like:
+
+```jsx
+const { user, session, error } = await supabase.auth.signIn({
+ email: '[email protected]',
+ password: 'example-password',
+})
+```
+
+If you want to request a feature, or contribute to the project directly, just head to https://github.com/supabase/gotrue and open some issues/PRs, we're always open to help.
+
+In the next guide we'll be looking at how to setup external OAuth providers: Watch [Part Five: Google Oauth](../../learn/auth-deep-dive/auth-google-oauth)
+
+### Resources
+
+- JWT debugger: https://jwt.io​
+
+### Next steps
+
+- Watch [Part One: JWTs](../../learn/auth-deep-dive/auth-deep-dive-jwts)
+- Watch [Part Two: Row Level Security](../../learn/auth-deep-dive/auth-row-level-security)
+- Watch [Part Three: Policies](../../learn/auth-deep-dive/auth-policies)
+<!-- - Watch [Part Four: GoTrue](../../learn/auth-deep-dive/auth-gotrue) -->
+- Watch [Part Five: Google Oauth](../../learn/auth-deep-dive/auth-google-oauth)
+- Sign up for Supabase: [app.supabase.com](https://app.supabase.com)
diff --git a/apps/temp-docs/docs/learn/auth-deep-dive/jwts.md b/apps/temp-docs/docs/learn/auth-deep-dive/jwts.md
new file mode 100644
index 00000000000..d2b084e3a6e
--- /dev/null
+++ b/apps/temp-docs/docs/learn/auth-deep-dive/jwts.md
@@ -0,0 +1,186 @@
+---
+id: auth-deep-dive-jwts
+title: 'Part One: JWTs'
+description: Supabase Auth Deep Dive Part 1 - JWTs
+---
+
+### About
+
+An introduction to JWTs and how they are used in Supabase Auth
+
+### Watch
+
+<div class="video-container">
+<iframe src="https://www.youtube-nocookie.com/embed/v3Exg5YpJvE" frameBorder="1" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
+</div>
+
+### What are JSON Web Tokens (JWTs)?
+
+JWTs are JSON objects that are encoded and signed and sent around as a string. They are distributed to users of a service or website, who can later show the JWT to the website or service as proof that they have the right to access certain content.
+
+What exactly do we mean when we say "encoded" and "signed"?
+
+Well, the JSON object starts out looking something like this:
+
+```js
+{
+ "sub": "0001",
+ "name": "Sam Vimes",
+ "iat": 1516239022,
+ "exp": 1518239022
+}
+```
+
+`sub` is the "subject", which is usually the UUID of the user. `name` is self-explanatory, and `iat` is the Unix timestamp at which the token was created. Many JWTs will also have an `exp`, which is the date at which the token is set to expire and can no longer be used. These are some of the standard fields you may find in a JWT, but you can pretty much store whatever you want in there, for example:
+
+```js
+{
+ "sub": "0002",
+ "name": "Věra Hrabánková",
+ "iat": 1516239022,
+ "exp": 1518239022,
+ "theme": {
+ "primary" : "#D80C14",
+ "secondary" : "#FFFFFF"
+ }
+}
+```
+
+Just note that the more data you store in your token, the longer the encoded string will be.
+
+When we want to send the JWT to the user, we first encode the data using an algorithm such as `HS256`. There are many libraries (and several different algorithms) that can be used to do this encoding/decoding, such as [jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken). I made a repl [here](https://replit.com/@awalias/jsonwebtokens#index.js) so you can try it for yourself. The signing is as simple as:
+
+```js
+// from https://replit.com/@awalias/jsonwebtokens#index.js
+let token = jwt.sign({ name: 'Sam Vimes' }, 'some-secret')
+```
+
+And the resulting string will look like this:
+
+```js
+eyJhbGciOiJIUzI1NiJ9
+ .eyJzdWIiOiIwMDAxIiwibmFtZSI6IlNhbSBWaW1lcyIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoxNTE4MjM5MDIyfQ
+ .zMcHjKlkGhuVsiPIkyAkB2rjXzyzJsMMgpvEGvGtjvA
+```
+
+You will notice that the string is actually made up of three components, which we'll address one by one:
+
+The first segment `eyJhbGciOiJIUzI1NiJ9` is known as the "header", and when decoded just tells us which algorithm was used to do the encoding:
+
+```js
+{
+ "alg": "HS256"
+}
+```
+
+The second segment `eyJzdWIiOiIwMDAxIiwibmFtZSI6IlNhbSBWaW1lcyIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoxNTE4MjM5MDIyfQ` contains our original payload:
+
+```js
+{
+ "sub": "0001",
+ "name": "Sam Vimes",
+ "iat": 1516239022,
+ "exp": 1518239022
+}
+```
+
+The last segment `zMcHjKlkGhuVsiPIkyAkB2rjXzyzJsMMgpvEGvGtjvA` is the signature itself, which is the part used by the website or service provider to verify that a token sent by some user is legitimate. It is produced in the first instance by running the cryptographic function HS256 on the following input:
+
+```js
+HMACSHA256(
+ base64UrlEncode(header) + "." +
+ base64UrlEncode(payload)
+ <jwt_secret>
+)
+```
+
+You can test out minting your own tokens on [https://jwt.io](https://jwt.io).
+
+It is important to note that anyone who possesses the `jwt_secret` here can create new tokens, and also verify existing ones. More advanced JWT algorithms use two secrets: one for the creation of tokens, and a separate one to verify the validity of signed tokens.
+
+You might wonder why JWTs are so popular all of a sudden. The answer is that with the mass adoption of microservice architecture, we were in a situation where several distinct microservices (APIs, websites, servers, etc.) want to easily validate that a user is who they say they are, or are in other words a "logged-in" user. Traditional session tokens are no use here, since they would require each microservice to either maintain a record of currently valid session tokens or to query a central database each time a user wants to access a resource in order to check the validity of the session token – very inefficient indeed. JWT-based auth in this sense is decentralized, since anyone with the `jwt_secret` can verify a token without needing access to a centralized database.
+
+Note: One downside of JWTs is that they are not easily voidable, like session tokens. If a JWT is leaked to a malicious actor, they will be able to redeem it anywhere until the expiry date is reached – unless of course the system owner updates the `jwt_secret` (which will of course invalidate _everyone's_ existing tokens).
+
+### JWTs in Supabase
+
+In Supabase we issue JWTs for three different purposes:
+
+1. `anon key`: This key is used to bypass the Supabase API gateway and can be used in your client-side code.
+2. `service role key`: This key has super admin rights and can bypass your Row Level Security. Do not put it in your client-side code. Keep it private.
+3. `user specific jwts`: These are tokens we issue to users who log into your project/service/website. It's the modern equivalent of a session token, and can be used by a user to access content or permissions specific to them.
+
+The first token here, the `anon key` token, is for developers to send along with their API requests whenever they want to interact with their Supabase database.
+
+Let's say you want to read the names of all the rows in a table `colors`. We would make a request like:
+
+```bash
+curl 'https://xscduanzzfseqszwzhcy.supabase.co/rest/v1/colors?select=name' \
+-H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYxNDIwNTE3NCwiZXhwIjoxOTI5NzgxMTc0fQ.-NBR1WnZyQGpRLdXJfgfpszoZ0EeE6KHatJsDPLIX8c"
+```
+
+If we put this token into https://jwt.io, we see it decodes to:
+
+```js
+{
+ "role": "anon",
+ "iss": "supabase",
+ "iat": 1614205174,
+ "exp": 1929781174
+}
+```
+
+This JWT is signed by a `jwt_secret` specific to the developer's Supabase token (you can find this secret alongside this encoded "anon key" on your Dashboard under Settings > API page) and is required to get past the Supabase API gateway and access the developer's project.
+
+The idea with this particular key is that it's safe to put into your client, meaning it's okay if your end users see this key – but _only_ if you first enable Row Level Security, which is the topic of [Part Two](../../learn/auth-deep-dive/auth-row-level-security) in this series.
+
+The second key, `service role key`, should only ever be used on one of your own servers or environments, and should never be shared with end users. You might use this token to do things like make batch inserts of data.
+
+The `user access token` is the JWT issued when you call for example:
+
+```js
+supabase.auth.signIn({
+ email: '[email protected]',
+ password: 'They_Live_1988!',
+})
+```
+
+This token should be passed in addition to the `apikey` header as an `Authorization Bearer` header like:
+
+```bash
+curl 'https://xscduanzzfseqszwzhcy.supabase.co/rest/v1/colors?select=name' \
+-H "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTYxNDIwNTE3NCwiZXhwIjoxOTI5NzgxMTc0fQ.-NBR1WnZyQGpRLdXJfgfpszoZ0EeE6KHatJsDPLIX8c" \
+-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjE1ODI0Mzg4LCJzdWIiOiIwMzM0NzQ0YS1mMmEyLTRhYmEtOGM4YS02ZTc0OGY2MmExNzIiLCJlbWFpbCI6InNvbWVvbmVAZW1haWwuY29tIiwiYXBwX21ldGFkYXRhIjp7InByb3ZpZGVyIjoiZW1haWwifSwidXNlcl9tZXRhZGF0YSI6bnVsbCwicm9sZSI6ImF1dGhlbnRpY2F0ZWQifQ.I-_oSsJamtinGxniPETBf-ezAUwDW2sY9bJIThvdX9s"
+```
+
+You'll notice that this token is quite a bit longer, since it contains information specific to the user such as:
+
+```js
+{
+ "aud": "authenticated",
+ "exp": 1615824388,
+ "sub": "0334744a-f2a2-4aba-8c8a-6e748f62a172",
+ "email": "[email protected]",
+ "app_metadata": {
+ "provider": "email"
+ },
+ "user_metadata": null,
+ "role": "authenticated"
+}
+```
+
+Now that you understand what JWTs are and where they're used in Supabase, you can explore how to use them in combination with Row Level Security to start restricting access to certain tables, rows, and columns in your Postgres database: [Part Two: Row Level Security](../../learn/auth-deep-dive/auth-row-level-security)
+
+### Resources
+
+- JWT debugger: https://jwt.io/
+
+### Next steps
+
+<!-- - Watch [Part One: JWTs](../../learn/auth-deep-dive/auth-deep-dive-jwts) -->
+
+- [Part Two: Row Level Security](../../learn/auth-deep-dive/auth-row-level-security)
+- [Part Three: Policies](../../learn/auth-deep-dive/auth-policies)
+- [Part Four: GoTrue](../../learn/auth-deep-dive/auth-gotrue)
+- [Part Five: Google Oauth](../../learn/auth-deep-dive/auth-google-oauth)
+- Sign up for Supabase: [app.supabase.com](https://app.supabase.com)
diff --git a/apps/temp-docs/docs/learn/auth-deep-dive/policies.md b/apps/temp-docs/docs/learn/auth-deep-dive/policies.md
new file mode 100644
index 00000000000..32c02e223ea
--- /dev/null
+++ b/apps/temp-docs/docs/learn/auth-deep-dive/policies.md
@@ -0,0 +1,167 @@
+---
+id: auth-policies
+title: 'Part Three: Policies'
+description: 'Supabase Auth Deep Dive Part 3: User Based Access Policies'
+---
+
+### About
+
+How to restrict table access to authenticated users, row level policies, and email domain based access.
+
+### Watch
+
+<div class="video-container">
+<iframe src="https://www.youtube-nocookie.com/embed/0LvCOlELs5U" frameBorder="1" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
+</div>
+
+### User based row level policies
+
+Now that we know how to restrict access to tables based on JWT roles, we can combine this with user management to give us much more control over what data your users can read to and write from your database.
+
+We'll start with how user sessions work in Supabase, and later move on to writing user-centric policies.
+
+Let's say we're signing a user up to our service for the first time. The typical way to do this is by invoking the following method in supabase-js:
+
+```jsx
+// see full api reference here: /docs/reference/javascript/auth-signup
+supabase.auth.signUp({ email, password })
+```
+
+By default this will send a confirmation email to the user. When the user clicks the link in the email, they will be redirected to your site (you need to provide your site url in Auth > Settings on the dashboard. By default this is http://localhost:3000) and the full URL including query params will look something like this:
+
+```
+http://localhost:3000/#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjE2NDI5MDY0LCJzdWIiOiI1YTQzNjVlNy03YzdkLTRlYWYtYThlZS05ZWM5NDMyOTE3Y2EiLCJlbWFpbCI6ImFudEBzdXBhYmFzZS5pbyIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIn0sInVzZXJfbWV0YWRhdGEiOnt9LCJyb2xlIjoiYXV0aGVudGljYXRlZCJ9.4IFzn4eymqUNYYo2AHLxNRL8m08G93Qcg3_fblGqDjo&expires_in=3600&refresh_token=RuioJv2eLV05lgH5AlJwTw&token_type=bearer&type=signup
+```
+
+Let's break this up so that it's easier to read:
+
+```jsx
+// the base url - whatever you set in the Auth Settings in app.supabase.com dashboard
+http://localhost:3000/
+
+// note we use the '#' (fragment) instead of '?' query param
+// the access token is a JWT issued to the user
+#access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjE2NDI5MDY0LCJzdWIiOiI1YTQzNjVlNy03YzdkLTRlYWYtYThlZS05ZWM5NDMyOTE3Y2EiLCJlbWFpbCI6ImFudEBzdXBhYmFzZS5pbyIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIn0sInVzZXJfbWV0YWRhdGEiOnt9LCJyb2xlIjoiYXV0aGVudGljYXRlZCJ9.4IFzn4eymqUNYYo2AHLxNRL8m08G93Qcg3_fblGqDjo
+
+// valid for 60 minutes by default
+&expires_in=3600
+
+// use to get a new access_token before 60 minutes expires
+&refresh_token=RuioJv2eLV05lgH5AlJwTw
+
+// can use as the Authorization: Bearer header in requests to your API
+&token_type=bearer
+
+// why was this token issued? was it a signup, login, password reset, or magic link?
+&type=signup
+```
+
+If we put the access_token into [https://jwt.io](https://jwt.io) we'll see it decodes to:
+
+```jsx
+{
+ "aud": "authenticated",
+ "exp": 1616429064,
+ "sub": "5a4365e7-7c7d-4eaf-a8ee-9ec9432917ca",
+ "email": "[email protected]",
+ "app_metadata": {
+ "provider": "email"
+ },
+ "user_metadata": {},
+ "role": "authenticated"
+}
+```
+
+The `authenticated` role is special in Supabase, it tells the API that this is an authenticated user and will know to compare the JWT against any policies you've added to the requested resource (table or row).
+
+The `sub` claim is usually what we use to match the JWT to rows in your database, since by default it is the unique identifier of the user in the `auth.users` table (as a side note - it's generally not recommended to alter the `auth` schema in any way in your Supabase database since the Auth API relies on it to function correctly).
+
+For the curious, try heading to the SQL editor and querying:
+
+```sql
+select * from auth.users;
+```
+
+If supabase-js is loaded on your site (in this case http://localhost:3000) it automatically plucks the `access_token` out of the URL and initiates a session. You can retrieve the [session](/docs/reference/javascript/auth-getsession) to see if there is a valid session:
+
+```jsx
+console.log(supabase.auth.getSession())
+```
+
+Now that we can use methods to issue JWTs to users, we want to start fetching resources specific to that user. So let's make some. Go to the SQL editor and run:
+
+```sql
+create table my_scores (
+ name text,
+ score int,
+ user_id uuid not null
+);
+
+ALTER TABLE my_scores ENABLE ROW LEVEL SECURITY;
+
+insert into my_scores(name, score, user_id)
+values
+ ('Paul', 100, '5a4365e7-7c7d-4eaf-a8ee-9ec9432917ca'),
+ ('Paul', 200, '5a4365e7-7c7d-4eaf-a8ee-9ec9432917ca'),
+ ('Leto', 50, '9ec94326-2e2d-2ea2-22e3-3a535a4365e7');
+
+-- use UUIDs from the auth.users table if you want to try it
+-- for yourself
+```
+
+Now we'll write our policy, again in SQL, but note it's also possible to add via the dashboard in Auth > Policies:
+
+```sql
+CREATE POLICY user_update_own_scores ON my_scores
+ FOR ALL
+ USING (auth.uid() = user_id);
+```
+
+Now, assuming you have an active session in your javascript/supabase-js environment you can do:
+
+```jsx
+supabase.from('my_scores').select('*').then(console.log)
+```
+
+and you should only receive scores belonging to the current logged in user. Alternatively you can use Bash like:
+
+```bash
+curl 'https://sjvwsaokcugktsdaxxze.supabase.co/rest/v1/my_scores?select=*' \
+-H "apikey: <ANON_KEY>" \
+-H "Authorization: Bearer <ACCESS_TOKEN>"
+```
+
+Note that the `anon key` (or `service role key`) is always needed to get past the API gateway. This can be passed in the `apikey` header or in a query param named `apikey`. It is passed automatically in supabase-js as long as you used it to instantiate the client.
+
+There are some more notes here on how to structure your schema to best integrate with the `auth.users` table.
+
+Once you get the hang of policies you can start to get a little bit fancy. Let's say I work at Blizzard and I only want Blizzard staff members to be able to update people's high scores, I can write something like:
+
+```sql
+create policy "Only Blizzard staff can update leaderboard"
+ on my_scores
+ for update using (
+ right(auth.jwt() ->> 'email', 13) = '@blizzard.com'
+ );
+```
+
+Supabase comes with two built-in helper functions: `auth.uid()` and `auth.jwt()`.
+
+See the full PostgreSQL policy docs here: [https://www.postgresql.org/docs/12/sql-createpolicy.html](https://www.postgresql.org/docs/12/sql-createpolicy.html)
+
+You can get as creative as you like with these policies.
+
+### Resources
+
+- JWT debugger: https://jwt.io​
+- PostgeSQL Policies: https://www.postgresql.org/docs/12/sql-createpolicy.html
+- PostgREST Row Level Security: https://postgrest.org/en/v7.0.0/auth.html
+
+### Next steps
+
+- Watch [Part One: JWTs](../../learn/auth-deep-dive/auth-deep-dive-jwts)
+- Watch [Part Two: Row Level Security](../../learn/auth-deep-dive/auth-row-level-security)
+<!-- - Watch [Part Three: Policies](../../learn/auth-deep-dive/auth-policies) -->
+- Watch [Part Four: GoTrue](../../learn/auth-deep-dive/auth-gotrue)
+- Watch [Part Five: Google Oauth](../../learn/auth-deep-dive/auth-google-oauth)
+- Sign up for Supabase: [app.supabase.com](https://app.supabase.com)
diff --git a/apps/temp-docs/docs/learn/auth-deep-dive/row-level-security.md b/apps/temp-docs/docs/learn/auth-deep-dive/row-level-security.md
new file mode 100644
index 00000000000..23acd52b98c
--- /dev/null
+++ b/apps/temp-docs/docs/learn/auth-deep-dive/row-level-security.md
@@ -0,0 +1,121 @@
+---
+id: auth-row-level-security
+title: 'Part Two: Row Level Security'
+description: Supabase Auth Deep Dive Part Two - Row Level Security
+---
+
+### About
+
+Learn how to restrict access to your database tables by enabling Row Level Security and writing Postgres Policies in the Supabase Dashboard.
+
+### Watch
+
+<div class="video-container">
+<iframe src="https://www.youtube-nocookie.com/embed/qY_iQ10IUhs" frameBorder="1" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
+</div>
+
+### Securing Your Tables
+
+In Supabase, you can access your data directly from the client (often the web browser), you do this by passing your Supabase URL and Anon key to supabase-js like so:
+
+```js
+const supabase = createClient(
+ 'https://qwertyuiop.supabase.co',
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
+)
+```
+
+This raises an interesting question however: "if my anon key is in the client, then can't someone read my javascript and steal my key?", the answer is yes. And this is where Postgres policies come in.
+
+Using Postgres's "Row-Level-Security" policies, we can set rules on what data the anon key is allowed or not allowed to access by default.
+
+We can say for example that the anon key should only be able to read from a particular table, but not write, update, nor delete.
+
+And these rules can be as complex as we want. We could say that the anon key can only delete rows which were inserted on a Thursday afternoon between 4 and 6pm, and where the id column is an even number. Pretty strange, but it shows the power of policies.
+
+Let's say we create a leaderboard table. We want people on our website to be able to read the leaderboard, but not write, update, or delete from it. We start by defining our table in SQL and adding some dummy data:
+
+```sql
+create table leaderboard (
+ name text,
+ score int
+);
+
+insert into leaderboard(name, score)
+values ('Paul', 100), ('Leto', 50), ('Chani', 200);
+```
+
+Now let's set up a client to read the data, I've created a repl here to show a living example: [https://replit.com/@awalias/supabase-leaderboard-demo#index.js](https://replit.com/@awalias/supabase-leaderboard-demo#index.js). If you copy the snippet you can plug in your own Supabase URL and anon key.
+
+You can see that it's possible to freely read from and write to the table by using:
+
+```js
+// Writing
+let { data, error } = await supabase
+ .from('leaderboard')
+ .insert({ name: 'Bob', score: 99999 })
+
+// Reading
+let { data, error } = await supabase
+ .from('leaderboard')
+ .select('name, score')
+ .order('score', { ascending: false })
+```
+
+Now let's restrict access. We'll start by fully restricting the table. We can do this in the SQL editor by making a query:
+
+```sql
+ALTER TABLE leaderboard ENABLE ROW LEVEL SECURITY;
+```
+
+or via the Supabase Dashboard, by navigating to Auth > Policies, and clicking the red padlock on the leaderboard table, so that it turns white.
+
+![Enable row level security in Supabase](/img/auth-deep-dive-2.png)
+
+You'll notice that both reading and writing now fail with an error like:
+
+```jsx
+{
+ hint: null,
+ details: null,
+ code: '42501',
+ message: 'new row violates row-level security policy for table "leaderboard"'
+}
+```
+
+Now we need to add a policy to enable reading of the table, for everyone who sends the anon key (JWT) in the `Authorization: Bearer` header.
+
+In SQL this can be done with:
+
+```sql
+CREATE POLICY anon_read_leaderboard ON leaderboard
+ FOR SELECT
+ TO 'anon'
+ USING (true);
+```
+
+`anon_read_leaderboard` here is just a name that you choose for your policy. `leaderboard` is the table name. `FOR SELECT` says that we only want this policy to apply for reads (or rather "selects" in SQL). `TO` means that this policy will only apply to the `anon` Postgres role. And finally the rule itself is `true'`, which means it will _allow_ any `selects` to the `anon` user.
+
+If you'd prefer to use the dashboard to add your policy you can do so by clicking "Add Policy" in the Policies tab and making a policy like this:
+
+![Add a read only policy in Supabase](/img/auth-deep-dive-2-2.png)
+
+You should now be able to read from your leaderboard, but will still not be able to write, update, or delete from it, which is exactly what we wanted!
+
+A quick reminder that you can always use your `service_role` API key to bypass these row level security policies. But be extra careful that you don't leak this key by including it in the client. This can be useful if you're building internal admin tools, or if you need to bulk insert or delete data via the API.
+
+In the next guide we will look at using Policies in combination with User Accounts, so that you can restrict access to data on a User by User basis: Watch [Part Three: Policies](../../learn/auth-deep-dive/auth-policies)
+
+### Resources
+
+- JWT debugger: https://jwt.io/
+- RESTED: https://github.com/RESTEDClient/RESTED
+
+### Next steps
+
+- Watch [Part One: JWTs](../../learn/auth-deep-dive/auth-deep-dive-jwts)
+<!-- - Watch [Part Two: Row Level Security](../../learn/auth-deep-dive/auth-row-level-security) -->
+- Watch [Part Three: Policies](../../learn/auth-deep-dive/auth-policies)
+- Watch [Part Four: GoTrue](../../learn/auth-deep-dive/auth-gotrue)
+- Watch [Part Five: Google Oauth](../../learn/auth-deep-dive/auth-google-oauth)
+- Sign up for Supabase: [app.supabase.com](https://app.supabase.com)