Add locale-prefixed routes for admin, auth, dashboard, and public pages. Add error, loading, and not-found pages for locale context. Add language switcher UI component for Vietnamese/English toggle. 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>
|
|
);
|
|
}
|