Skip to content

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

migrate(docs): troubleshooting 8 (#30939)

Charis25306236eafa
diff --git a/apps/docs/content/troubleshooting/not-receiving-auth-emails-from-the-supabase-project-OFSNzw.mdx b/apps/docs/content/troubleshooting/not-receiving-auth-emails-from-the-supabase-project-OFSNzw.mdx
new file mode 100644
index 00000000000..60b5266f964
--- /dev/null
+++ b/apps/docs/content/troubleshooting/not-receiving-auth-emails-from-the-supabase-project-OFSNzw.mdx
@@ -0,0 +1,28 @@
+---
+title = "Not receiving Auth emails from the Supabase project"
+github_url = "https://github.com/orgs/supabase/discussions/22610"
+date_created = "2024-04-10T05:18:51+00:00"
+topics = ["auth", "platform"]
+keywords = ["smtp", "email", "delivery", "logs", "provider", "firewalls"]
+---
+
+**We strongly recommend configuring your own custom SMTP provider** in your projects to avoid running into issues with sending emails from your project. The built-in email provider is for demonstration purposes only and offers a very low rate limit. You can read more details about the rate limits [here](https://supabase.com/docs/guides/platform/going-into-prod#auth-rate-limits).
+
+If you're testing your Supabase projects, consider configuring an email testing tool like [Mailtrap](https://mailtrap.io/) to test your emails. It's an email sandbox tool that helps debug emails without actually sending an email to an end user.
+
+As the initial step in debugging not-delivered emails, check your project's [Auth logs](https://supabase.com/dashboard/project/_/logs/auth-logs) for errors that can occur when handing over to the email providers. In general, handover issues can occur due to misconfiguration of the custom SMTP provider.
+
+Once handed over to the email provider, Supabase has no control over email delivery. There can be multiple reasons why emails do not reach the user's inbox.
+
+#### 1. Issues with the email provider.
+
+The email provider's logs are the next place to look for email delivery issues. There are cases where the email provider blocks the delivery due to past bounced-back emails. Some email providers maintain a suppression list for not sending emails due to several reasons. You can read more about it here - https://sendgrid.com/en-us/blog/what-is-a-suppression-list
+
+#### 2. Issues with the user's email server
+
+Many email firewalls maintain a denylist of IPs and domain names for security reasons and as spam filters. Sometimes, they block incoming emails from unknown addresses with certain keywords such as password reset, verification link, etc. In these cases, ask the user to check with their email server admin to see if they are blocking your email domain or quarantining the incoming emails. If you use the default provider, the email domain is `supabase.io`. Some information on email firewalls are available here - https://mailchimp.com/help/about-email-firewalls/.
+
+I haven't mentioned the most obvious cases, like checking a user's spam inbox. However, It's worth noting that sometimes this can happen with a default provider. It's also one of the reasons that you should configure your own email provider where you have more control over email delivery.
+
+References:
+Configure a Custom SMTP - https://supabase.com/docs/guides/auth/auth-smtp
diff --git a/apps/docs/content/troubleshooting/oauth-sign-in-isnt-redirecting-on-the-server-side-ShGMtr.mdx b/apps/docs/content/troubleshooting/oauth-sign-in-isnt-redirecting-on-the-server-side-ShGMtr.mdx
new file mode 100644
index 00000000000..59cebbbf9f6
--- /dev/null
+++ b/apps/docs/content/troubleshooting/oauth-sign-in-isnt-redirecting-on-the-server-side-ShGMtr.mdx
@@ -0,0 +1,45 @@
+---
+title = "OAuth sign in isn't redirecting on the server side"
+github_url = "https://github.com/orgs/supabase/discussions/15862"
+date_created = "2023-07-18T12:28:55+00:00"
+topics = ["auth"]
+keywords = ["oauth", "redirects", "server-side"]
+---
+
+The reason behind this limitation is that the auth helpers library lacks a direct mechanism for performing server-side redirects, as each framework handles redirects differently. However, the library does offer a URL through the data property it returns, which should be utilized for the purpose of redirection.
+
+**NextJS:**
+
+```ts
+import { NextResponse } from "next/server";
+...
+const { data } = await supabase.auth.signInWithOAuth({
+ provider: 'github',
+})
+
+return NextResponse.redirect(data.url)
+```
+
+**SvelteKit:**
+
+```ts
+import { redirect } from '@sveltejs/kit';
+...
+const { data } = await supabase.auth.signInWithOAuth({
+ provider: 'github',
+})
+
+throw redirect(303, data.url)
+```
+
+**Remix:**
+
+```ts
+import { redirect } from "@remix-run/node"; // or cloudflare/deno
+...
+const { data } = await supabase.auth.signInWithOAuth({
+ provider: 'github',
+})
+
+return redirect(data.url)
+```
diff --git a/apps/docs/content/troubleshooting/resolving-500-status-authentication-errors-7bU5U8.mdx b/apps/docs/content/troubleshooting/resolving-500-status-authentication-errors-7bU5U8.mdx
new file mode 100644
index 00000000000..23feebc4ea9
--- /dev/null
+++ b/apps/docs/content/troubleshooting/resolving-500-status-authentication-errors-7bU5U8.mdx
@@ -0,0 +1,192 @@
+---
+title = "Resolving 500 Status Authentication Errors"
+github_url = "https://github.com/orgs/supabase/discussions/28652"
+date_created = "2024-08-15T01:07:10+00:00"
+topics = ["auth", "database"]
+keywords = ["authentication", "smtp", "database", "logs", "error"]
+
+[[errors]]
+http_status_code = 500
+---
+
+# Resolving 500 Status Authentication Errors
+
+A 500 error in Auth typically indicates an issue with an external dependency, such as your database or SMTP provider, rather than with Auth itself. This guide will help you explore the Auth logs to identify the underlying cause.
+
+### Prerequisites
+
+#### Open the Log Explorer
+
+Ensure you have access to the [Dashboard's Log Explorer](https://supabase.com/dashboard/project/_/logs/explorer) and set the time range appropriately:
+
+![image](/docs/img/troubleshooting/152d65ad-f0ed-47cf-8dcb-1e31c6221e71.png)
+
+#### Improving log readability
+
+Logs are displayed in a table format, which can be challenging to read. Double-clicking on a row will expand it for easier viewing:
+
+<img
+ width="1012"
+ alt="Screenshot 2024-08-14 at 1 15 26 PM"
+ src="https://github.com/user-attachments/assets/6f4c833c-ae15-41e1-9aa8-48ebd58741a1"
+/>
+
+## Section 1: Checking for Database-Level Errors
+
+### Query for Recent Database Errors
+
+Use the following SQL query to check for any recent errors the Auth server encountered while interacting with your database:
+
+```sql
+select
+ cast(postgres_logs.timestamp as datetime) as timestamp,
+ event_message,
+ parsed.error_severity,
+ parsed.user_name,
+ parsed.query,
+ parsed.detail,
+ parsed.hint,
+ parsed.sql_state_code,
+ parsed.backend_type
+from
+ postgres_logs
+ cross join unnest(metadata) as metadata
+ cross join unnest(metadata.parsed) as parsed
+where
+ regexp_contains(parsed.error_severity, 'ERROR|FATAL|PANIC')
+ and regexp_contains(parsed.user_name, 'supabase_auth_admin')
+order by timestamp desc
+limit 100;
+```
+
+If no results are returned, proceed to Section 2.
+
+### Common Database-Level Errors
+
+There are few known categories of auth/database level errors:
+
+### Constraint Related (sql_state_code = 23503 or 23\*)
+
+If you’ve manually created a foreign key relationship between your tables and those in the `auth` schema, a constraint may prevent the Auth server from updating the `auth.users` table.
+
+#### Solution
+
+The log will show the name of the constraint. You need `DROP` it:
+
+```sql
+ALTER TABLE <your table> DROP CONSTRAINT <constraint name>;
+```
+
+Alternatively, you can `DROP` and then recreate the constraint with a less restrictive modifier, such as `SET NULL`, `SET DEFAULT`, or `CASCADE`:
+
+```sql
+BEGIN;
+ALTER TABLE <your table> DROP CONSTRAINT <constraint name>;
+
+ALTER TABLE <your table> ADD CONSTRAINT <constraint name> FOREIGN KEY (<column name>)
+ REFERENCES auth.users (<auth.users column>)
+ ON DELETE SET NULL;
+COMMIT;
+```
+
+### Ownership related (sql_state_code = 42501)
+
+If you see an error like must be owner of..., the supabase_auth_admin role may have lost privileges over tables in the auth schema. This often results from faulty migrations by external ORMs (e.g., Prisma) or manual schema modifications.
+
+#### Solution
+
+Check ownership with this [GitHub Gist](https://gist.github.com/TheOtherBrian1/6aaaa78632b1e371f3b1c790305f0acd). If any objects are owned by the `supabase_admin` role, contact [Support](https://supabase.com/dashboard/support/new). If they're owned by roles other than `supabase_auth_admin` you can change ownership back manually one-by-one:
+
+```sql
+ALTER <object type (table, function, etc.)> <auth.object_name> OWNER TO supabase_auth_admin;
+```
+
+Alternatively, you can run the SQL script in this [Github Gist](https://gist.github.com/TheOtherBrian1/4714a333432b80660ff71b136b298fb8) to change all
+
+### Trigger related:
+
+If errors reference a database function, this indicates a trigger error on one of the auth tables (likely auth.users). If you do not want to keep the trigger/function, you can just quickly drop it, otherwise, continue reading to know how to fix the issue:
+
+```sql
+-- delete the trigger with the following SQL:
+DROP FUNCTION <function name>() CASCADE;
+
+-- If you'd prefer, you can drop the trigger alone with the following query:
+-- DROP TRIGGER <trigger_name> on auth.<table_name>;
+```
+
+#### Solutions:
+
+Get the function's definition with this query:
+
+```
+select pg_get_functiondef(oid)
+from pg_proc
+where proname = '<FUNCTION NAME>';
+```
+
+##### Trigger has insufficient privileges ( sql_state_code = 42501)
+
+If the error is related to insufficient privileges, your trigger function is missing a security definer tag, which allows it to access schemas outside of auth. You must `REPLACE` the function with the appropriate security definer settings ([example](https://supabase.com/docs/guides/database/functions?queryGroups=language&language=js#security-definer-vs-invoker))
+
+##### Trigger references a table or column that does not exist (sql_state_code = 42P01)
+
+The trigger may be referencing a table or column that no longer exists. In that case do one of the three:
+
+- make sure the trigger is referencing the table using the right schema, e.g. public, auth, etc.
+- modify the trigger function to reference the appropriate database objects.
+- remove the trigger
+- recreate the database object that the trigger referenced
+
+### Corrupted Schema
+
+If you made any customizations to the auth schema, such as adding RLS, modifying table columns, or adding/dropping tables, it can break migrations done by the Auth Server. It's necessary to remove these changes and restore the auth schema to its original form.
+
+## Section 2: Checking Auth level errors
+
+### Query for Auth Errors
+
+Run this SQL query in the Log Explorer to find Auth-related errors:
+
+```sql
+select
+ cast(metadata.timestamp as datetime) as timestamp,
+ msg,
+ event_message,
+ status,
+ path,
+ level
+from auth_logs
+cross join unnest(metadata) as metadata
+where
+ -- find all errors
+ status::INT = 500
+ OR
+ regexp_contains(level, 'error|fatal')
+order by timestamp
+```
+
+### Database Migration Errors
+
+> "running db migrations: Migrator: problem creating schema migrations"
+
+This is a continuation of the "Corrupted Schema" error from the Postgres Section. If you modified structures in the auth schema, such as columns or tables, or added restrictions, such as RLS, Auth will not be able to complete it's migrations. It's necessary to remove those modifications.
+
+If you are running older versions of auth, you may experience a migration bug. If so, checkout this [guide](https://github.com/orgs/supabase/discussions/20722) for a resolution. If it doesn't work, please contact Support.
+
+### SMTP errors
+
+The logs may contain messages about `gomail`. It means that auth is struggling to communicate with the SMTP provider. This often implies that:
+
+1. Misconfigured custom domain name with your email provider.
+2. Invalid email port usage.
+3. Rate limiting by the SMTP provider.
+4. SMTP provider downtime.
+
+The log will be able to provide some context for what is occurring, but it is important to check with your external SMTP provider to make sure everything is properly configured.
+
+## Step 3: Checking Email Templates
+
+Incomplete or incorrect email templates can also cause 500 errors. If your templates have unclosed variable tags or HTML elements, or use forbidden characters, this might be the issue.
+
+Test a simplified email template in the [Auth Dashboard](https://supabase.com/dashboard/project/_/auth/templates). If the new template works, revise your original template to avoid forbidden characters and ensure all elements/variables are properly closed.
diff --git a/apps/docs/content/troubleshooting/security-of-anonymous-sign-ins-iOrGCL.mdx b/apps/docs/content/troubleshooting/security-of-anonymous-sign-ins-iOrGCL.mdx
new file mode 100644
index 00000000000..94e2c79918b
--- /dev/null
+++ b/apps/docs/content/troubleshooting/security-of-anonymous-sign-ins-iOrGCL.mdx
@@ -0,0 +1,26 @@
+---
+title = "Security of Anonymous Sign-ins"
+github_url = "https://github.com/orgs/supabase/discussions/22856"
+date_created = "2024-04-18T07:45:51+00:00"
+topics = ["auth", "platform"]
+keywords = ["anonymous", "security", "sign-in", "authentication", "identity", "policies"]
+---
+
+We want to clarify and provide reassurance on this topic.
+
+### Security Overview:
+
+Enabling anonymous sign-ins on your project does not reduce its security. Here's why:
+
+- Same as Regular Users: Anonymous users function just like regular users within your project. They have unique user IDs and their own records in the authentication tables.
+- Security Policies: All role-based security policies (RLS) applicable to regular users also apply to anonymous users.
+- Identity Verification Measures: Even though anonymous users do not initially provide an email or phone number, the security of your project remains robust. But to prevent misuse, we recommend implementing additional security measure such as [CAPTCHA](https://supabase.com/docs/guides/auth/auth-captcha): to ensure that interactions are genuinely human.
+
+### Practical Use Cases:
+
+- Demo Mode: You can enable users to try out your product in a demo mode without full account creation.
+- Feature Restrictions: You can limit certain actions (like posting public content) to users who sign up with more identifiable information (e.g., Google or Apple sign-ins), while still allowing anonymous users to explore your app.
+
+Remember, the underlying security of your project will remain the same. If your project was secure before enabling anonymous sign-ins, it will continue to be secure afterward. It's important to review and adjust your RLS policies regularly to align with your security and business needs.
+
+If you have further questions or need assistance in setting up, please don't hesitate to contact the [support team](https://supabase.com/dashboard/support/new).
diff --git a/apps/docs/content/troubleshooting/security-of-anonymous-sign-ins-uw6_Dw.mdx b/apps/docs/content/troubleshooting/security-of-anonymous-sign-ins-uw6_Dw.mdx
new file mode 100644
index 00000000000..6edae6bf8df
--- /dev/null
+++ b/apps/docs/content/troubleshooting/security-of-anonymous-sign-ins-uw6_Dw.mdx
@@ -0,0 +1,46 @@
+---
+title = "Security of anonymous sign-ins"
+github_url = "https://github.com/orgs/supabase/discussions/22855"
+date_created = "2024-04-18T07:44:47+00:00"
+topics = ["auth", "database", "platform", "storage"]
+keywords = ["anonymous", "security", "sign-in", "auth", "jwt"]
+---
+
+A common concern is that enabling anonymous sign-ins on your project decreases its security. This is not true, and hopefully this thread will help you grasp why.
+
+Anonymous users are just users that don't have an email address or phone number associated yet. Otherwise, they are just like any other user in the system. They have their own row in `auth.users`, their own unique user ID, etc.
+
+All RLS policies in place for regular users also apply to anonymous users. Therefore, the security of the project does not decrease. To further illustrate this, let's briefly forget that anonymous users exist.
+
+Let's imagine a human trying to trick the project's Auth system, so they use a temp-mail service (like DuckDuckGo's duck.com or any of the multitude temp-mail services out there) to sign up. That user account has an email address, but it's not a particularly _identifying_ one. You can't link it to a human, and in fact the email address may not exist 5 minutes later.
+
+What I just described is the anonymous sign-ins feature, just implemented differently.
+
+Therefore, if the project has a security issue _before_ enabling anonymous sign-ins, they will continue to have the same security issue. If they don't have one, they will continue to not have one after enabling.
+
+So what's the deal then? Anonymous sign-ins (like the temp-mail case above) can be slightly easier to abuse with bots and scripts than OAuth sign-in methods. For this reason turn on CAPTCHA which ensures to some degree of certainty that it's humans and not scripts behind the sign-ins.
+
+Supabase Auth exposes the `is_anonymous` claim in the user's JWT if that user comes from a `supabase.auth.signInAnonymously()` call. This is mainly a _restrictive_ feature. Let's look at some examples of how it can be used.
+
+Suppose your project uses only Google and Apple sign-in, which to a high degree of certainty enforce "humanness." (You have to give up your address, real phone number, they track your phone etc.) But, you're faced with an adoption problem. Folks are not signing up because they want to try out the product first without giving their user data.
+
+One way to solve this is to add "demo mode" in your project. This will allow users to try out the real product without committing their personal data or money ahead. But this poses an issue for you -- you don't want "spam" on your platform, and you certainly don't want all features to be available without having some way to identify the human behind the actions.
+
+To put this in practical terms, let's imagine you're building a blogging platform.
+
+Users that are _quite human_ (like coming from Google or Apple) get all features. This is because you could, eventually, sue them for harassment, pornography, etc.
+
+But users in "demo mode" don't get all features. Maybe they can only:
+
+- Write blog posts as drafts, but not publish them. (Goal: Users should experience the great writing experience.)
+ - This can be achieved by, for example, restricting `INSERT` and `UPDATE` on the `public.posts` table when `auth.jwt()->>'is_anonymous'` is true.
+- Don't allow users to attach pictures to posts. (Goal: Storage costs money, and you don't want anonymous users to upload inappropriate content.)
+ - Use [Storage RLS](https://supabase.com/docs/guides/storage/security/access-control) policies to restrict uploads when `is_anonymous` is true.
+- Prevent anonymous users from commenting on the blogging platform, but being able to read all comments. (Goal: Keep an orderly platform.)
+ - This can be achieved by restricting `INSERT` on the `public.comments` table but allow `SELECT` when `is_anonymous` is true.
+
+Resources:
+
+- Postgres RLS policies (permissive vs restrictive): https://www.postgresql.org/docs/current/ddl-rowsecurity.html
+- Supabase Anonymous sign-ins docs: https://supabase.com/docs/guides/auth/auth-anonymous
+- Storage access control (RLS): https://supabase.com/docs/guides/storage/security/access-control
diff --git a/apps/docs/content/troubleshooting/should-i-set-a-shorter-max-age-parameter-on-the-cookies-8sbF4V.mdx b/apps/docs/content/troubleshooting/should-i-set-a-shorter-max-age-parameter-on-the-cookies-8sbF4V.mdx
new file mode 100644
index 00000000000..aa4bdcd1e92
--- /dev/null
+++ b/apps/docs/content/troubleshooting/should-i-set-a-shorter-max-age-parameter-on-the-cookies-8sbF4V.mdx
@@ -0,0 +1,11 @@
+---
+title = "Should I set a shorter Max-Age parameter on the cookies?"
+github_url = "https://github.com/orgs/supabase/discussions/18870"
+date_created = "2023-11-10T11:53:00+00:00"
+topics = ["auth"]
+keywords = ["cookies", "max-age", "browser", "session"]
+---
+
+The `Max-Age` or `Expires` cookie parameters only control whether the browser sends the value to the server. Since a refresh token represents the long-lived authentication session of the user on that browser, setting a short `Max-Age` or `Expires` parameter on the cookies only results in a degraded user experience.
+
+The only way to ensure that a user has logged out or their session has ended is to get the user's details with `getUser()`.
diff --git a/apps/docs/content/troubleshooting/using-google-smtp-with-supabase-custom-smtp-ZZzU4Y.mdx b/apps/docs/content/troubleshooting/using-google-smtp-with-supabase-custom-smtp-ZZzU4Y.mdx
new file mode 100644
index 00000000000..81baedc3aca
--- /dev/null
+++ b/apps/docs/content/troubleshooting/using-google-smtp-with-supabase-custom-smtp-ZZzU4Y.mdx
@@ -0,0 +1,35 @@
+---
+title = "Using Google SMTP with Supabase Custom SMTP"
+github_url = "https://github.com/orgs/supabase/discussions/19646"
+date_created = "2023-12-13T01:40:37+00:00"
+topics = ["auth", "platform"]
+keywords = ["smtp", "google", "workspace", "2FA", "TLS", "encryption", "port"]
+---
+
+Hey everyone, i've been hearing feedback about how challenging it can be to get google SMTP working properly with Supabase. I've tried setting this up with a trial google workspace account and this is what i've discovered.
+
+1. The sender email and SMTP username has to be your google workspace admin email.
+2. The SMTP password used has to be an app password. Google workspace doesn't make it easy to to figure out how to create this. You need to **enable 2FA** on your workspace account first (not inside the admin console but in https://myaccount.google.com/)
+3. If you want to use `smtp-relay.gmail.com` only port 465 works. If you want to use `smtp.gmail.com`, you can use port 465 or 587 (both ports worked for me).
+
+I'm also gonna include some screenshots below on what those steps look like:
+
+## For `smtp-relay.gmail.com`
+
+![image](/docs/img/troubleshooting/800448a1-0245-4a26-855f-3be8f44adf03.png)
+
+(The "Require TLS encryption" option doesn't seem to affect anything during my testing)
+![image](/docs/img/troubleshooting/5b55ddbc-abfc-4c66-a012-b8e4d23cd438.png)
+
+## For `smtp.gmail.com`
+
+![image](/docs/img/troubleshooting/ade24c85-50b5-47ca-a2ce-c3f77a0e128a.png)
+
+A lot of this was figured out through trial and error - i don't have explanations as to why only port 465 works with `smtp-relay.gmail.com` and / or why the TLS encryption option has no effect on SMTP.
+
+As to whether this is a Supabase Auth bug, i highly doubt that it is because we use the [native golang smtp library ](https://pkg.go.dev/net/smtp). If anyone still has issues getting google SMTP to work, i would recommend to switch to one of these SMTP providers:
+
+- [Resend](https://resend.com/blog/how-to-configure-supabase-to-send-emails-from-your-domain)
+- [Sendgrid](https://sendgrid.com/en-us)
+- [Mailgun](https://www.mailgun.com/)
+- AWS SES SMTP
diff --git a/apps/docs/public/img/troubleshooting/152d65ad-f0ed-47cf-8dcb-1e31c6221e71.png b/apps/docs/public/img/troubleshooting/152d65ad-f0ed-47cf-8dcb-1e31c6221e71.png
new file mode 100644
index 00000000000..348f6b063a1
Binary files /dev/null and b/apps/docs/public/img/troubleshooting/152d65ad-f0ed-47cf-8dcb-1e31c6221e71.png differ
diff --git a/apps/docs/public/img/troubleshooting/5b55ddbc-abfc-4c66-a012-b8e4d23cd438.png b/apps/docs/public/img/troubleshooting/5b55ddbc-abfc-4c66-a012-b8e4d23cd438.png
new file mode 100644
index 00000000000..f8742c40f46
Binary files /dev/null and b/apps/docs/public/img/troubleshooting/5b55ddbc-abfc-4c66-a012-b8e4d23cd438.png differ
diff --git a/apps/docs/public/img/troubleshooting/800448a1-0245-4a26-855f-3be8f44adf03.png b/apps/docs/public/img/troubleshooting/800448a1-0245-4a26-855f-3be8f44adf03.png
new file mode 100644
index 00000000000..2296a7fa06a
Binary files /dev/null and b/apps/docs/public/img/troubleshooting/800448a1-0245-4a26-855f-3be8f44adf03.png differ
diff --git a/apps/docs/public/img/troubleshooting/ade24c85-50b5-47ca-a2ce-c3f77a0e128a.png b/apps/docs/public/img/troubleshooting/ade24c85-50b5-47ca-a2ce-c3f77a0e128a.png
new file mode 100644
index 00000000000..7c7accbc092
Binary files /dev/null and b/apps/docs/public/img/troubleshooting/ade24c85-50b5-47ca-a2ce-c3f77a0e128a.png differ