fix auth
This commit is contained in:
parent
f8ce3ee759
commit
570b93b74c
@ -1,6 +1,7 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server'
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
import { prisma } from '@/lib/prisma'
|
import { prisma } from '@/lib/prisma'
|
||||||
import { createServerSupabaseClient } from '@/lib/supabase-server'
|
import { auth } from '@/lib/auth'
|
||||||
|
import { headers } from 'next/headers'
|
||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
@ -8,16 +9,17 @@ export async function POST(
|
|||||||
) {
|
) {
|
||||||
const { id } = await params
|
const { id } = await params
|
||||||
try {
|
try {
|
||||||
const supabase = await createServerSupabaseClient()
|
const session = await auth.api.getSession({
|
||||||
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
|
headers: await headers()
|
||||||
|
})
|
||||||
if (authError || !supabaseUser) {
|
|
||||||
|
if (!session?.user) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is admin
|
// Check if user is admin
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { id: supabaseUser.id },
|
where: { id: session.user.id },
|
||||||
select: { isAdmin: true }
|
select: { isAdmin: true }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server'
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
import { prisma } from '@/lib/prisma'
|
import { prisma } from '@/lib/prisma'
|
||||||
import { createServerSupabaseClient } from '@/lib/supabase-server'
|
import { auth } from '@/lib/auth'
|
||||||
|
import { headers } from 'next/headers'
|
||||||
|
|
||||||
export async function POST(
|
export async function POST(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
@ -8,16 +9,17 @@ export async function POST(
|
|||||||
) {
|
) {
|
||||||
const { id } = await params
|
const { id } = await params
|
||||||
try {
|
try {
|
||||||
const supabase = await createServerSupabaseClient()
|
const session = await auth.api.getSession({
|
||||||
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
|
headers: await headers()
|
||||||
|
})
|
||||||
if (authError || !supabaseUser) {
|
|
||||||
|
if (!session?.user) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is admin
|
// Check if user is admin
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { id: supabaseUser.id },
|
where: { id: session.user.id },
|
||||||
select: { isAdmin: true }
|
select: { isAdmin: true }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
import { prisma } from '@/lib/prisma'
|
import { prisma } from '@/lib/prisma'
|
||||||
import { createServerSupabaseClient } from '@/lib/supabase-server'
|
import { auth } from '@/lib/auth'
|
||||||
|
import { headers } from 'next/headers'
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
try {
|
||||||
const supabase = await createServerSupabaseClient()
|
const session = await auth.api.getSession({
|
||||||
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
|
headers: await headers()
|
||||||
|
})
|
||||||
if (authError || !supabaseUser) {
|
|
||||||
|
if (!session?.user) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is admin
|
// Check if user is admin
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { id: supabaseUser.id },
|
where: { id: session.user.id },
|
||||||
select: { isAdmin: true }
|
select: { isAdmin: true }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextResponse } from 'next/server'
|
||||||
import { prisma } from '@/lib/prisma'
|
import { prisma } from '@/lib/prisma'
|
||||||
import { createServerSupabaseClient } from '@/lib/supabase-server'
|
import { auth } from '@/lib/auth'
|
||||||
|
import { headers } from 'next/headers'
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
try {
|
||||||
const supabase = await createServerSupabaseClient()
|
const session = await auth.api.getSession({
|
||||||
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
|
headers: await headers()
|
||||||
|
})
|
||||||
if (authError || !supabaseUser) {
|
|
||||||
|
if (!session?.user) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if user is admin
|
// Check if user is admin
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: { id: supabaseUser.id },
|
where: { id: session.user.id },
|
||||||
select: { isAdmin: true }
|
select: { isAdmin: true }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useTranslations } from 'next-intl'
|
import { useTranslations } from 'next-intl'
|
||||||
import { useAuthUser } from '@/hooks/useAuthUser'
|
import { useBetterAuth } from '@/hooks/useBetterAuth'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { ThemeToggle, MobileThemeToggle } from '@/components/ui/theme-toggle'
|
import { ThemeToggle, MobileThemeToggle } from '@/components/ui/theme-toggle'
|
||||||
import { LanguageToggle, MobileLanguageToggle } from '@/components/ui/language-toggle'
|
import { LanguageToggle, MobileLanguageToggle } from '@/components/ui/language-toggle'
|
||||||
@ -12,7 +12,7 @@ import { Logo } from '@/components/ui/logo'
|
|||||||
import { Menu, X } from 'lucide-react'
|
import { Menu, X } from 'lucide-react'
|
||||||
|
|
||||||
export function Header() {
|
export function Header() {
|
||||||
const { user, signOut } = useAuthUser()
|
const { user, signOut } = useBetterAuth()
|
||||||
const t = useTranslations('navigation')
|
const t = useTranslations('navigation')
|
||||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import { Button } from '@/components/ui/button'
|
|||||||
import { LegacyAvatar } from '@/components/ui/avatar'
|
import { LegacyAvatar } from '@/components/ui/avatar'
|
||||||
import { ChevronDown, User as UserIcon, LogOut, Settings, CreditCard, Receipt } from 'lucide-react'
|
import { ChevronDown, User as UserIcon, LogOut, Settings, CreditCard, Receipt } from 'lucide-react'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { useAuthUser } from '@/hooks/useAuthUser'
|
import { useBetterAuth } from '@/hooks/useBetterAuth'
|
||||||
import { useRouter } from 'next/navigation'
|
import { useRouter } from 'next/navigation'
|
||||||
|
|
||||||
interface UserAvatarDropdownProps {
|
interface UserAvatarDropdownProps {
|
||||||
@ -25,7 +25,7 @@ export function MobileUserMenu({
|
|||||||
className
|
className
|
||||||
}: UserAvatarDropdownProps) {
|
}: UserAvatarDropdownProps) {
|
||||||
const t = useTranslations('navigation')
|
const t = useTranslations('navigation')
|
||||||
const { isAdmin } = useAuthUser()
|
const { isAdmin } = useBetterAuth()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const userName = user.name || user.email?.split('@')[0] || 'User'
|
const userName = user.name || user.email?.split('@')[0] || 'User'
|
||||||
@ -129,7 +129,7 @@ export function UserAvatarDropdown({
|
|||||||
className
|
className
|
||||||
}: UserAvatarDropdownProps) {
|
}: UserAvatarDropdownProps) {
|
||||||
const t = useTranslations('navigation')
|
const t = useTranslations('navigation')
|
||||||
const { isAdmin } = useAuthUser()
|
const { isAdmin } = useBetterAuth()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user