mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-06 03:30:25 -05:00
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
import { oAuthLoginGetToken } from '@/services/common/oauth';
|
|
import { getAllUrlParams, getRedirectUrl, setAuthorization } from '@/utils/common';
|
|
import { usePathname, useRouter } from 'next/navigation';
|
|
import { useEffect } from 'react';
|
|
|
|
interface CertificationProps {
|
|
platform: string;
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export default function Certification({ platform, children }: CertificationProps) {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
|
|
useEffect(() => {
|
|
const searchParams = getAllUrlParams();
|
|
oAuthLoginGetToken({
|
|
method: platform,
|
|
callback: searchParams,
|
|
// @ts-ignore
|
|
invite: localStorage.getItem('invite') || '',
|
|
})
|
|
.then((res) => {
|
|
const token = res?.data?.data?.token;
|
|
if (!token) {
|
|
throw new Error('Invalid token');
|
|
}
|
|
setAuthorization(token);
|
|
router.replace(getRedirectUrl());
|
|
router.refresh();
|
|
})
|
|
.catch((error) => {
|
|
router.replace('/auth');
|
|
});
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [pathname]);
|
|
|
|
return children;
|
|
}
|