mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
* Add Supabase adapter * Add Supabase adapter * Add schema setup to docs * supabase config changes * chore: update to supabase-js v2. * chore: migrate to next_auth schema. * feat: add supabase examples. * chore: update docs. * chore: add telemetry. * fix: resolve issues after merge. * chore: extend session type. * typo * chore: remove unnecessary grants. * fix: schema constraints. Co-authored-by: thorwebdev <thor@supabase.io> Co-authored-by: Thor 雷神 Schaeff <5748289+thorwebdev@users.noreply.github.com> Co-authored-by: Thang Vu <hi@thvu.dev>
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
import Layout from "../components/layout"
|
|
import { useState, useEffect } from "react"
|
|
import { useSession } from "next-auth/react"
|
|
import { createClient } from "@supabase/supabase-js"
|
|
|
|
export default function Page() {
|
|
const { data: session } = useSession()
|
|
const [data, setData] = useState(null)
|
|
|
|
useEffect(() => {
|
|
if (session) {
|
|
console.log(session)
|
|
// User is logged in, let's fetch their data.
|
|
const { supabaseAccessToken } = session
|
|
const supabase = createClient(
|
|
process.env.NEXT_PUBLIC_SUPABASE_URL,
|
|
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
|
{
|
|
global: {
|
|
headers: { Authorization: `Bearer ${supabaseAccessToken}` },
|
|
},
|
|
}
|
|
)
|
|
// Fetch data with RLS enabled.
|
|
supabase
|
|
.from("users")
|
|
.select("*")
|
|
.then(({ data }) => setData(data))
|
|
}
|
|
}, [session])
|
|
|
|
return (
|
|
<Layout>
|
|
<h1>Fetch Data from Supabase with RLS</h1>
|
|
<h2>Client-side data fetching with RLS:</h2>
|
|
<pre>{JSON.stringify(data, null, 2)}</pre>
|
|
<h2>API Example</h2>
|
|
<p>
|
|
You can also use Supabase in API routes. See the code in the
|
|
`/pages/api/examples/supabase-rls.js` file.
|
|
</p>
|
|
<p>
|
|
<em>You must be signed in to see responses.</em>
|
|
</p>
|
|
<p>/api/examples/supabase-rls</p>
|
|
<iframe src="/api/examples/supabase-rls" />
|
|
</Layout>
|
|
)
|
|
}
|