- Fix Next.js build failure: remove duplicate route at (dashboard)/listings/[id] that conflicted with (public)/listings/[id] (same URL path in two route groups) - Fix 772 ESLint errors: auto-fix import ordering (import-x/order), remove unused imports/variables, convert empty interfaces to type aliases, replace require() with ESM imports, fix consistent-type-imports violations - Add CLAUDE.md for developer onboarding documentation - All checks pass: 0 lint errors, typecheck clean, 230 tests passing, build success Co-Authored-By: Paperclip <noreply@paperclip.ing>
56 lines
1.6 KiB
TypeScript
56 lines
1.6 KiB
TypeScript
'use client';
|
|
|
|
import { Loader2 } from 'lucide-react';
|
|
import { useRouter, useSearchParams } from 'next/navigation';
|
|
import { useEffect, useRef } from 'react';
|
|
import { useAuthStore } from '@/lib/auth-store';
|
|
|
|
export default function GoogleCallbackPage() {
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
const { handleOAuthCallback } = useAuthStore();
|
|
const processed = useRef(false);
|
|
|
|
useEffect(() => {
|
|
if (processed.current) return;
|
|
processed.current = true;
|
|
|
|
const accessToken = searchParams.get('accessToken');
|
|
const refreshToken = searchParams.get('refreshToken');
|
|
const expiresIn = searchParams.get('expiresIn');
|
|
const error = searchParams.get('error');
|
|
|
|
if (error) {
|
|
router.replace(`/login?error=${encodeURIComponent(error)}`);
|
|
return;
|
|
}
|
|
|
|
if (!accessToken || !refreshToken) {
|
|
router.replace('/login?error=oauth_failed');
|
|
return;
|
|
}
|
|
|
|
handleOAuthCallback(
|
|
accessToken,
|
|
refreshToken,
|
|
expiresIn ? Number(expiresIn) : 900,
|
|
)
|
|
.then(() => {
|
|
const redirect = searchParams.get('redirect') || '/dashboard';
|
|
router.replace(redirect);
|
|
})
|
|
.catch(() => {
|
|
router.replace('/login?error=oauth_failed');
|
|
});
|
|
}, [searchParams, handleOAuthCallback, router]);
|
|
|
|
return (
|
|
<div className="flex min-h-screen items-center justify-center">
|
|
<div className="text-center">
|
|
<Loader2 className="mx-auto h-8 w-8 animate-spin text-primary" />
|
|
<p className="mt-4 text-sm text-muted-foreground">Đang xử lý đăng nhập Google...</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|