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>
31 lines
1014 B
JavaScript
31 lines
1014 B
JavaScript
// This is an example of how to query data from Supabase with RLS.
|
|
// Learn more about Row Levele Security (RLS): https://supabase.com/docs/guides/auth/row-level-security
|
|
import { unstable_getServerSession } from "next-auth/next"
|
|
import { authOptions } from "../auth/[...nextauth]"
|
|
import { createClient } from "@supabase/supabase-js"
|
|
|
|
export default async (req, res) => {
|
|
const session = await unstable_getServerSession(req, res, authOptions)
|
|
|
|
if (!session)
|
|
return res.send(JSON.stringify({ error: "No session!" }, null, 2))
|
|
|
|
const { supabaseAccessToken } = session
|
|
|
|
const supabase = createClient(
|
|
process.env.NEXT_PUBLIC_SUPABASE_URL,
|
|
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
|
{
|
|
global: {
|
|
headers: {
|
|
Authorization: `Bearer ${supabaseAccessToken}`,
|
|
},
|
|
},
|
|
}
|
|
)
|
|
// Now you can query with RLS enabled.
|
|
const { data, error } = await supabase.from("users").select("*")
|
|
|
|
res.send(JSON.stringify({ supabaseAccessToken, data, error }, null, 2))
|
|
}
|