28 lines
663 B
TypeScript
28 lines
663 B
TypeScript
// app/page.tsx
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
import { redirect } from 'next/navigation'
|
|
import { createClient } from '@/lib/supabase/server'
|
|
import { getRoleHome, isValidRole, type UserRole } from '@/lib/auth/roles'
|
|
|
|
export default async function RootPage() {
|
|
const supabase = await createClient()
|
|
const {
|
|
data: { user },
|
|
} = await supabase.auth.getUser()
|
|
|
|
if (!user) redirect('/login')
|
|
|
|
const { data: profile } = await supabase
|
|
.from('users')
|
|
.select('role')
|
|
.eq('id', user.id)
|
|
.single()
|
|
|
|
if (profile?.role && isValidRole(profile.role)) {
|
|
redirect(getRoleHome(profile.role as UserRole))
|
|
}
|
|
|
|
redirect('/login')
|
|
}
|