42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { headers } from 'next/headers'
|
|
import { redirect } from 'next/navigation'
|
|
import { getServerSession } from 'next-auth'
|
|
|
|
import { authOptions } from '@/lib/auth'
|
|
import { getConfiguredDingtalkCorpId, normalizeDingtalkCorpId } from '@/lib/dingtalk-corp'
|
|
import { normalizeInternalRedirectPath } from '@/lib/safe-redirect'
|
|
import DingtalkEntryClient from './DingtalkEntryClient'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
export const revalidate = 0
|
|
|
|
type DingtalkEntryPageProps = {
|
|
searchParams?: {
|
|
redirect?: string
|
|
corpId?: string
|
|
corpid?: string
|
|
}
|
|
}
|
|
|
|
export default async function DingtalkEntryPage({ searchParams }: DingtalkEntryPageProps) {
|
|
const redirectPath = normalizeInternalRedirectPath(searchParams?.redirect, '/performance-survey')
|
|
if (
|
|
redirectPath.startsWith('/task-detail-change-requests/')
|
|
&& !/DingTalk/i.test(headers().get('user-agent') || '')
|
|
) {
|
|
const session = await getServerSession(authOptions)
|
|
redirect(session?.user ? redirectPath : `/login?redirect=${encodeURIComponent(redirectPath)}`)
|
|
}
|
|
|
|
const corpId =
|
|
normalizeDingtalkCorpId(searchParams?.corpId || searchParams?.corpid) ||
|
|
getConfiguredDingtalkCorpId()
|
|
|
|
return (
|
|
<DingtalkEntryClient
|
|
corpId={corpId}
|
|
redirectPath={redirectPath}
|
|
/>
|
|
)
|
|
}
|