The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: remix auth helper docs.
thorwebdev7743351b4546
diff --git a/apps/reference/docs/guides/auth/auth-helpers/nextjs.mdx b/apps/reference/docs/guides/auth/auth-helpers/nextjs.mdxindex b69b42d8936..4e8ffdd87dc 100644--- a/apps/reference/docs/guides/auth/auth-helpers/nextjs.mdx+++ b/apps/reference/docs/guides/auth/auth-helpers/nextjs.mdx@@ -300,7 +300,7 @@ export const getServerSideProps = withPageAuth({## Server-side data fetching to OAuth APIs using `provider_token`-When using third-party auth providers, sessions are initiated with an additional `provider_token` field which is persisted as an HTTPOnly cookie upon logging in to enabled usage on the server side. The `provider_token` can be used to make API requests to the OAuth provider's API endpoints on behalf of the logged-in user. In the following example, we fetch the user's full profile from the third-party API during SSR using their id and auth token:+When using third-party auth providers, sessions are initiated with an additional `provider_token` field which is persisted in the auth cookie and can be accessed within the session object. The `provider_token` can be used to make API requests to the OAuth provider's API endpoints on behalf of the logged-in user.```jsimport { User, withPageAuth } from '@supabase/auth-helpers-nextjs'diff --git a/apps/reference/docs/guides/auth/auth-helpers/remix.mdx b/apps/reference/docs/guides/auth/auth-helpers/remix.mdxindex 029b876d7b7..fcfd3c57c0e 100644--- a/apps/reference/docs/guides/auth/auth-helpers/remix.mdx+++ b/apps/reference/docs/guides/auth/auth-helpers/remix.mdx@@ -63,18 +63,18 @@ SUPABASE_ANON_KEY=YOUR_SUPABASE_ANON_KEY]}><TabItem value="js">-Loader functions run on the server immediately before the component is rendered. They respond to all GET requests on a route. You can create an authenticated Supabase client by calling the `createSupabaseClient` function and passing it your `SUPABASE_URL`, `SUPABASE_ANON_KEY`, and a `Request` and `Response`.+Loader functions run on the server immediately before the component is rendered. They respond to all GET requests on a route. You can create an authenticated Supabase client by calling the `createServerClient` function and passing it your `SUPABASE_URL`, `SUPABASE_ANON_KEY`, and a `Request` and `Response`.```jsximport { json } from '@remix-run/node' // change this import to whatever runtime you are using-import { createSupabaseClient } from '@supabase/auth-helpers-remix'+import { createServerClient } from '@supabase/auth-helpers-remix'export const loader = async ({ request }) => {const response = new Response()// an empty response is required for the auth helpers// to set cookies to manage auth- const supabaseClient = createSupabaseClient(+ const supabaseClient = createServerClient(process.env.SUPABASE_URL,process.env.SUPABASE_ANON_KEY,{ request, response }@@ -98,11 +98,11 @@ export const loader = async ({ request }) => {</TabItem><TabItem value="ts">-Loader functions run on the server immediately before the component is rendered. You can create an authenticated Supabase client by calling the `createSupabaseClient` function and passing it your `SUPABASE_URL`, `SUPABASE_ANON_KEY`, and a `Request` and `Response`.+Loader functions run on the server immediately before the component is rendered. You can create an authenticated Supabase client by calling the `createServerClient` function and passing it your `SUPABASE_URL`, `SUPABASE_ANON_KEY`, and a `Request` and `Response`.```jsximport { LoaderFunction, json } from '@remix-run/node' // change this import to whatever runtime you are using-import { createSupabaseClient } from '@supabase/auth-helpers-remix'+import { createServerClient } from '@supabase/auth-helpers-remix'export const loader: LoaderFunction = async ({request,@@ -110,7 +110,7 @@ export const loader: LoaderFunction = async ({request: Request,}) => {const response = new Response()- const supabaseClient = createSupabaseClient(+ const supabaseClient = createServerClient(process.env.SUPABASE_URL,process.env.SUPABASE_ANON_KEY,{ request, response }@@ -142,16 +142,16 @@ export const loader: LoaderFunction = async ({]}><TabItem value="js">-Action functions run on the server and respond to HTTP requests to a route, other than GET - POST, PUT, PATCH, DELETE etc. You can create an authenticated Supabase client by calling the `createSupabaseClient` function and passing it your `SUPABASE_URL`, `SUPABASE_ANON_KEY`, and a `Request` and `Response`.+Action functions run on the server and respond to HTTP requests to a route, other than GET - POST, PUT, PATCH, DELETE etc. You can create an authenticated Supabase client by calling the `createServerClient` function and passing it your `SUPABASE_URL`, `SUPABASE_ANON_KEY`, and a `Request` and `Response`.```jsximport { json } from '@remix-run/node' // change this import to whatever runtime you are using-import { createSupabaseClient } from '@supabase/auth-helpers-remix'+import { createServerClient } from '@supabase/auth-helpers-remix'export const action = async ({ request }) => {const response = new Response()- const supabaseClient = createSupabaseClient(+ const supabaseClient = createServerClient(process.env.SUPABASE_URL,process.env.SUPABASE_ANON_KEY,{ request, response }@@ -173,11 +173,11 @@ export const action = async ({ request }) => {</TabItem><TabItem value="ts">-Action functions run on the server and respond to HTTP requests to a route, other than GET - POST, PUT, PATCH, DELETE etc. You can create an authenticated Supabase client by calling the `createSupabaseClient` function and passing it your `SUPABASE_URL`, `SUPABASE_ANON_KEY`, and a `Request` and `Response`.+Action functions run on the server and respond to HTTP requests to a route, other than GET - POST, PUT, PATCH, DELETE etc. You can create an authenticated Supabase client by calling the `createServerClient` function and passing it your `SUPABASE_URL`, `SUPABASE_ANON_KEY`, and a `Request` and `Response`.```jsximport { ActionFunction, json } from '@remix-run/node' // change this import to whatever runtime you are using-import { createSupabaseClient } from '@supabase/auth-helpers-remix'+import { createServerClient } from '@supabase/auth-helpers-remix'export const action: ActionFunction = async ({request,@@ -186,7 +186,7 @@ export const action: ActionFunction = async ({}) => {const response = new Response()- const supabaseClient = createSupabaseClient(+ const supabaseClient = createServerClient(process.env.SUPABASE_URL,process.env.SUPABASE_ANON_KEY,{ request, response }@@ -283,7 +283,10 @@ import {ScrollRestoration,useLoaderData,} from '@remix-run/react'-import { createSupabaseClient } from '@supabase/auth-helpers-remix'+import {+ createBrowserClient,+ createServerClient,+} from '@supabase/auth-helpers-remix'export const meta = () => ({charset: 'utf-8',@@ -378,7 +381,10 @@ import {ScrollRestoration,useLoaderData,} from '@remix-run/react'-import { createSupabaseClient } from '@supabase/auth-helpers-remix'+import {+ createBrowserClient,+ createServerClient,+} from '@supabase/auth-helpers-remix'export const meta: MetaFunction = () => ({charset: 'utf-8',@@ -831,80 +837,68 @@ const supabaseClient = createBrowserClient<Database>(## Server-side data fetching to OAuth APIs using `provider_token`-When using third-party auth providers, sessions are initiated with an additional `provider_token` field which is persisted as an HTTPOnly cookie upon logging in to enabled usage on the server side. The `provider_token` can be used to make API requests to the OAuth provider's API endpoints on behalf of the logged-in user. In the following example, we fetch the user's full profile from the third-party API using their id and auth token:+When using third-party auth providers, sessions are initiated with an additional `provider_token` field which is persisted in the auth cookie and can be accessed within the session object. The `provider_token` can be used to make API requests to the OAuth provider's API endpoints on behalf of the logged-in user.-```jsx-import { User, createServerClient } from '@supabase/auth-helpers-remix'-import { ActionFunction, json, redirect } from '@remix-run/node' // change this import to whatever runtime you are using-import { createServerClient } from '@supabase/auth-helpers-remix'--interface Profile {- /* ... */-}+```js+import { json, LoaderFunction, redirect } from '@remix-run/node'; // change this import to whatever runtime you are using+import { useLoaderData } from '@remix-run/react';+import { createServerClient, User } from '@supabase/auth-helpers-remix';+import { Database } from '../../db_types';export const loader: LoaderFunction = async ({- request,+ request}: {- request: Request,+ request: Request;}) => {- const response = new Response()- const supabaseClient = createServerClient(- process.env.SUPABASE_URL,- process.env.SUPABASE_ANON_KEY,+ const response = new Response();++ const supabaseClient = createServerClient<Database>(+ process.env.SUPABASE_URL!,+ process.env.SUPABASE_ANON_KEY!,{ request, response }- )+ );const {- data: { session },- } = await supabaseClient.auth.getSession()-- const user = session?.user-- if (!user) {- // there is no user, therefore, we are redirecting- // to the landing page. we still need to return- // response.headers to attach the set-cookie header- return redirect('/', {- headers: response.headers,- })- }-- // Retrieve provider_token from cookies- const provider_token = request.headers.get('sb-provider-token')+ data: { session }+ } = await supabaseClient.auth.getSession();- if (!provider_token) {- // there is no provider_token, therefore, we are redirecting+ if (!session) {+ // there is no session, therefore, we are redirecting// to the landing page. we still need to return// response.headers to attach the set-cookie headerreturn redirect('/', {- headers: response.headers,- })+ headers: response.headers+ });}- // Get logged in user's third-party id from metadata- const userId = user?.user_metadata.provider_id+ // Retrieve provider_token & logged in user's third-party id from metadata+ const { provider_token, user } = session;+ const userId = user.user_metadata.user_name;const allRepos = await (await fetch(`https://api.github.com/search/repositories?q=user:${userId}`, {method: 'GET',headers: {- Authorization: `token ${provider_token}`,- },+ Authorization: `token ${provider_token}`+ }})- ).json()+ ).json();// in order for the set-cookie header to be set,- // headers must be returned as part of the action response+ // headers must be returned as part of the loader responsereturn json(- { allRepos, user },+ { user, allRepos },{- headers: response.headers,+ headers: response.headers}- )-}+ );+};++export default function ProtectedPage() {+ // by fetching the user in the loader, we ensure it is available+ // for first SSR render - no flashing of incorrect state+ const { user, allRepos } = useLoaderData<{ user: User; allRepos: any }>();-export default function Page() {- const { allRepos, user } = useLoaderData()- return <pre>{JSON.stringify({ allRepos, user }, null, 2)}</pre>+ return <pre>{JSON.stringify({ user, allRepos }, null, 2)}</pre>;}```