feat(web): add i18n locale routes and language switcher component
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>
This commit is contained in:
55
apps/web/app/[locale]/auth/callback/google/page.tsx
Normal file
55
apps/web/app/[locale]/auth/callback/google/page.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
'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>
|
||||
);
|
||||
}
|
||||
55
apps/web/app/[locale]/auth/callback/zalo/page.tsx
Normal file
55
apps/web/app/[locale]/auth/callback/zalo/page.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
'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 ZaloCallbackPage() {
|
||||
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 Zalo...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user