Skip to content

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

Add frequently asked questions to the auth helpers

Andrew Smith9efa18be5398
diff --git a/apps/docs/components/MDX/auth_helpers_faq.mdx b/apps/docs/components/MDX/auth_helpers_faq.mdx
new file mode 100644
index 00000000000..0f9a289d784
--- /dev/null
+++ b/apps/docs/components/MDX/auth_helpers_faq.mdx
@@ -0,0 +1,31 @@
+### Fetch requests to API endpoints aren't showing the session
+
+You must pass along the cookie header with the fetch request in order for your API endpoint to get access to the cookie from this request.
+
+```ts
+const res = await fetch('http://localhost/contact', {
+ headers: {
+ cookie: headers().get('cookie') as string,
+ },
+})
+```
+
+### Performing administration tasks on the server side with the `service_role` `secret`
+
+By default, the auth-helpers do not permit the use of the `service_role` `secret`. This restriction is in place to prevent the accidental exposure of your `service_role` `secret` to the public. Since the auth-helpers function on both the server and client side, it becomes challenging to separate the key specifically for client-side usage.
+
+However, there is a solution. You can create a separate Supabase client using the `createClient` method from `@supabase/supabase-js` and provide it with the `service_role` `secret`. In a server environment, you will also need to disable certain properties to ensure proper functionality.
+
+By implementing this approach, you can safely utilize the `service_role` `secret` without compromising security or exposing sensitive information to the public.
+
+```ts
+import { createClient } from '@supabase/supabase-js'
+
+const supabase = createClient(supabaseUrl, serviceRoleSecret, {
+ auth: {
+ persistSession: false,
+ autoRefreshToken: false,
+ detectSessionInUrl: false,
+ },
+})
+```
diff --git a/apps/docs/components/index.tsx b/apps/docs/components/index.tsx
index 5a50214c12e..2e999d38a66 100644
--- a/apps/docs/components/index.tsx
+++ b/apps/docs/components/index.tsx
@@ -22,6 +22,7 @@ import QuickstartIntro from './MDX/quickstart_intro.mdx'
import SocialProviderSettingsSupabase from './MDX/social_provider_settings_supabase.mdx'
import SocialProviderSetup from './MDX/social_provider_setup.mdx'
import StorageManagement from './MDX/storage_management.mdx'
+import AuthHelpersFAQ from './MDX/auth_helpers_faq.mdx'
import { CH } from '@code-hike/mdx/components'
import RefHeaderSection from './reference/RefHeaderSection'
@@ -74,6 +75,7 @@ const components = {
SocialProviderSettingsSupabase,
StepHikeCompact,
StorageManagement,
+ AuthHelpersFAQ,
Mermaid,
Extensions,
Alert: (props: any) => (
diff --git a/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx b/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx
index 1ed17f68303..f2656c65f1d 100644
--- a/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx
+++ b/apps/docs/pages/guides/auth/auth-helpers/nextjs.mdx
@@ -854,6 +854,24 @@ See [refreshing session example](/docs/guides/auth/auth-helpers/nextjs#managing-
- [Protected Routes](https://github.com/supabase/supabase/tree/master/examples/auth/nextjs/app/[id]/page.tsx)
- [Conditional Rendering in Client Components with SSR](https://github.com/supabase/supabase/tree/master/examples/auth/nextjs/app/login-form.tsx)
+## Frequently asked questions
+
+<AuthHelpersFAQ />
+
+### OAuth sign in isn't redirecting on the 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 utilised for the purpose of redirection.
+
+```ts
+import { NextResponse } from "next/server";
+...
+const { data } = await supabase.auth.signInWithOAuth({
+ provider: 'github',
+})
+
+return NextResponse.redirect(data.url)
+```
+
## Migration Guide
### Migrating to v0.7.X
diff --git a/apps/docs/pages/guides/auth/auth-helpers/remix.mdx b/apps/docs/pages/guides/auth/auth-helpers/remix.mdx
index e1769bca84d..7a23dd8a272 100644
--- a/apps/docs/pages/guides/auth/auth-helpers/remix.mdx
+++ b/apps/docs/pages/guides/auth/auth-helpers/remix.mdx
@@ -745,6 +745,24 @@ export default function Index() {
> Ensure you have [enabled replication](https://supabase.com/dashboard/project/_/database/replication) on the table you are subscribing to.
+## Frequently asked questions
+
+<AuthHelpersFAQ />
+
+### OAuth sign in isn't redirecting on the 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 utilised for the purpose of redirection.
+
+```ts
+import { redirect } from "@remix-run/node"; // or cloudflare/deno
+...
+const { data } = await supabase.auth.signInWithOAuth({
+ provider: 'github',
+})
+
+return redirect(data.url)
+```
+
## Migration Guide
### Migrating to v0.2.0
diff --git a/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx b/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx
index 10fdf26cd6e..20dc807645b 100644
--- a/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx
+++ b/apps/docs/pages/guides/auth/auth-helpers/sveltekit.mdx
@@ -749,6 +749,24 @@ export const actions = {
}
```
+## Frequently asked questions
+
+<AuthHelpersFAQ />
+
+### OAuth sign in isn't redirecting on the 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 utilised for the purpose of redirection.
+
+```ts
+import { redirect } from '@sveltejs/kit';
+...
+const { data } = await supabase.auth.signInWithOAuth({
+ provider: 'github',
+})
+
+throw redirect(303, data.url)
+```
+
## Migration Guide [#migration]
### Migrate to 0.10