feat(auth): protect dashboard and add settings page
Add isAuthenticated check to dashboard with redirect to sign-in. Move settings page to locale segment. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
85ea4e6200
commit
3dc0d0713f
2 changed files with 66 additions and 0 deletions
43
src/app/[locale]/dashboard/page.tsx
Normal file
43
src/app/[locale]/dashboard/page.tsx
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { getTranslations } from 'next-intl/server';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from '@/components/ui/card';
|
||||||
|
import { isAuthenticated } from '@/lib/auth-server';
|
||||||
|
import { routes } from '@/lib/routes';
|
||||||
|
|
||||||
|
export default async function DashboardPage() {
|
||||||
|
const authenticated = await isAuthenticated();
|
||||||
|
|
||||||
|
if (!authenticated) {
|
||||||
|
const searchParams = new URLSearchParams({
|
||||||
|
callbackURL: routes.private.dashboard,
|
||||||
|
});
|
||||||
|
redirect(`${routes.public.signIn}?${searchParams.toString()}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const t = await getTranslations('DashboardPage');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="mx-auto flex min-h-[calc(100vh-8rem)] w-full max-w-4xl px-4 py-8 sm:px-6 lg:px-8">
|
||||||
|
<Card className="w-full">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle>{t('SecurityCardTitle')}</CardTitle>
|
||||||
|
<CardDescription>{t('SecurityCardDescription')}</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Button asChild>
|
||||||
|
<Link href={routes.private.settings}>{t('SecurityCardAction')}</Link>
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
23
src/app/[locale]/settings/page.tsx
Normal file
23
src/app/[locale]/settings/page.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
import { PasswordChangeCard } from '@/components/settings/PasswordChangeCard';
|
||||||
|
import { isAuthenticated } from '@/lib/auth-server';
|
||||||
|
import { routes } from '@/lib/routes';
|
||||||
|
|
||||||
|
export default async function SettingsPage() {
|
||||||
|
const authenticated = await isAuthenticated();
|
||||||
|
|
||||||
|
if (!authenticated) {
|
||||||
|
const searchParams = new URLSearchParams({
|
||||||
|
callbackURL: routes.private.settings,
|
||||||
|
});
|
||||||
|
|
||||||
|
redirect(`${routes.public.signIn}?${searchParams.toString()}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className="mx-auto flex min-h-[calc(100vh-8rem)] w-full max-w-2xl items-start px-4 py-8 sm:px-6 lg:px-8">
|
||||||
|
<PasswordChangeCard />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue