forked from supabase-community/vercel-ai-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
32 lines (28 loc) · 938 Bytes
/
auth.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import 'server-only'
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'
import { createClient } from '@/utils/supabase/server'
import { cookies } from 'next/headers'
// Old auth function
export const auth = async ({
cookieStore
}: {
cookieStore: ReturnType<typeof cookies>
}) => {
// Create a Supabase client configured to use cookies
const supabase = createClient()
const { data, error } = await supabase.auth.getSession()
if (error) throw error
return data.session
}
export const authUser = async () => {
// Create a Supabase client configured to use cookies
// const supabase = createServerComponentClient({
// cookies: () => cookieStore
// })
const supabase = createClient()
const { data, error } = await supabase.auth.getUser()
// const supabase = createClient()
// const { data:data, error:error } = await supabase.auth.getUser()
if (error) throw error
return data
}