feat: implement complex selection flow
This commit is contained in:
50
apps/frontend/src/routes/auth-callback.tsx
Normal file
50
apps/frontend/src/routes/auth-callback.tsx
Normal file
@@ -0,0 +1,50 @@
|
||||
import { useEffect } from 'react';
|
||||
import { apiClient } from '@/lib/api-client';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { createFileRoute, useNavigate } from '@tanstack/react-router';
|
||||
|
||||
function AuthCallbackPage() {
|
||||
const navigate = useNavigate();
|
||||
const { isAuthenticated } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
async function handleCallback() {
|
||||
if (!isAuthenticated) {
|
||||
navigate({ to: '/login' });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const complexes = await apiClient.complexes.listMine();
|
||||
|
||||
if (complexes.length === 1) {
|
||||
await apiClient.complexes.select({ complexId: complexes[0].id });
|
||||
navigate({ to: '/' });
|
||||
} else if (complexes.length > 1) {
|
||||
const current = await apiClient.complexes.getCurrent();
|
||||
if (current) {
|
||||
navigate({ to: '/' });
|
||||
} else {
|
||||
navigate({ to: '/select-complex' });
|
||||
}
|
||||
} else {
|
||||
navigate({ to: '/' });
|
||||
}
|
||||
} catch {
|
||||
navigate({ to: '/login' });
|
||||
}
|
||||
}
|
||||
|
||||
handleCallback();
|
||||
}, [isAuthenticated, navigate]);
|
||||
|
||||
return (
|
||||
<main className="flex min-h-screen w-full items-center justify-center px-6">
|
||||
<p className="text-sm text-muted-foreground">Completando sesión...</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
export const Route = createFileRoute('/auth-callback')({
|
||||
component: AuthCallbackPage,
|
||||
});
|
||||
Reference in New Issue
Block a user