完善认证功能,添加实名认证和回调处理逻辑
This commit is contained in:
76
src/app/(api)/identify/callback/page.tsx
Normal file
76
src/app/(api)/identify/callback/page.tsx
Normal file
@@ -0,0 +1,76 @@
|
||||
'use client'
|
||||
import {useEffect, useState} from 'react'
|
||||
import {useSearchParams} from 'next/navigation'
|
||||
import {IdentifyCallback} from '@/actions/auth/identify'
|
||||
import {Card, CardContent} from '@/components/ui/card'
|
||||
import {CheckCircle, AlertCircle, Loader2} from 'lucide-react'
|
||||
|
||||
export type PageProps = {}
|
||||
|
||||
export default function Page(props: PageProps) {
|
||||
const params = useSearchParams()
|
||||
const success = params.get('success') === 'true'
|
||||
const id = params.get('id') || ''
|
||||
|
||||
const [result, setResult] = useState({
|
||||
status: 'load',
|
||||
message: '处理中',
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (success) {
|
||||
IdentifyCallback({id}).then(resp => {
|
||||
if (!resp.success) {
|
||||
setResult({
|
||||
status: 'fail',
|
||||
message: resp.message || '获取活体检测结果失败',
|
||||
})
|
||||
}
|
||||
else {
|
||||
const data = resp.data
|
||||
setResult({
|
||||
status: data.success ? 'done' : 'fail',
|
||||
message: data.message || data.success
|
||||
? '认证已完成'
|
||||
: '认证失败',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
else {
|
||||
setResult({
|
||||
status: 'fail',
|
||||
message: '未完成认证',
|
||||
})
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className={`w-full min-h-screen flex justify-center items-center bg-blue-50`}>
|
||||
<Card className="w-full max-w-xs border-none shadow-none bg-white -translate-y-1/3">
|
||||
<CardContent className="flex flex-col items-center gap-4 py-6">
|
||||
{result.status === 'load' ? (<>
|
||||
<Loader2 className="w-16 h-16 text-primary animate-spin"/>
|
||||
<p className={`text-primary text-xl`}>{result.message}</p>
|
||||
<p className={`text-weak text-sm`}>
|
||||
请保持网络畅通
|
||||
</p>
|
||||
</>) : result.status === 'done' ? (<>
|
||||
<CheckCircle className="w-16 h-16 text-done"/>
|
||||
<p className={`text-done text-xl`}>{result.message}</p>
|
||||
<p className={`text-weak text-sm`}>
|
||||
认证已完成,您现在可以关闭此页面
|
||||
</p>
|
||||
</>) : (<>
|
||||
<AlertCircle className="w-16 h-16 text-fail"/>
|
||||
<p className={`text-fail text-xl`}>{result.message}</p>
|
||||
<p className={`text-weak text-sm`}>
|
||||
认证失败,请重新发起认证
|
||||
</p>
|
||||
</>)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user