Skip to content

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

docs: add error handling to redirect urls section (#22081)

Kang Mingd7c2dc0a3312
diff --git a/apps/docs/content/guides/auth/concepts/redirect-urls.mdx b/apps/docs/content/guides/auth/concepts/redirect-urls.mdx
index 2fcd240acd8..e1d7f014bad 100644
--- a/apps/docs/content/guides/auth/concepts/redirect-urls.mdx
+++ b/apps/docs/content/guides/auth/concepts/redirect-urls.mdx
@@ -81,3 +81,16 @@ const { data, error } = await supabase.auth.signInWithOAuth({
For mobile applications you can use deep linking URIs. For example, for your `SITE_URL` you can specify something like `com.supabase://login-callback/` and for additional redirect URLs something like `com.supabase.staging://login-callback/` if needed.
Read more about deep linking and find code examples for different frameworks [here](/docs/guides/auth/native-mobile-deep-linking).
+
+## Error Handling
+
+When authentication fails, the user will still be redirected to the redirect URL provided. However, the error details will be returned as query fragments in the URL. You can parse these query fragments and show a custom error message to the user. For example:
+
+```js
+const params = new URLSearchParams(window.location.hash.slice())
+
+if (params.get('error_code').startsWith('4')) {
+ // show error message if error is a 4xx error
+ window.alert(params.get('error_description'))
+}
+```
diff --git a/apps/docs/content/guides/auth/server-side-rendering.mdx b/apps/docs/content/guides/auth/server-side-rendering.mdx
index 78e0d7e31c4..ad5473b285d 100644
--- a/apps/docs/content/guides/auth/server-side-rendering.mdx
+++ b/apps/docs/content/guides/auth/server-side-rendering.mdx
@@ -153,7 +153,7 @@ This is traditionally done by setting cookies. Here's an example you can add to
```typescript
supabase.auth.onAuthStateChange((event, session) => {
- if (event === 'SIGNED_OUT' || event === 'USER_DELETED') {
+ if (event === 'SIGNED_OUT') {
// delete cookies on sign out
const expires = new Date(0).toUTCString()
document.cookie = `my-access-token=; path=/; expires=${expires}; SameSite=Lax; secure`