clean routes
This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
'use client';
|
||||
|
||||
import { AuthGuard } from '@/lib/gateways/AuthGuard';
|
||||
import { ReactNode } from 'react';
|
||||
import { headers } from 'next/headers';
|
||||
import { createRouteGuard } from '@/lib/auth/createRouteGuard';
|
||||
|
||||
interface SponsorLayoutProps {
|
||||
children: ReactNode;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sponsor Layout
|
||||
*
|
||||
*
|
||||
* Provides authentication protection for all sponsor-related routes.
|
||||
* Wraps children with AuthGuard to ensure only authenticated users can access.
|
||||
* Uses RouteGuard to enforce access control server-side.
|
||||
*/
|
||||
export default function SponsorLayout({ children }: SponsorLayoutProps) {
|
||||
export default async function SponsorLayout({ children }: SponsorLayoutProps) {
|
||||
const headerStore = await headers();
|
||||
const pathname = headerStore.get('x-pathname') || '/';
|
||||
|
||||
const guard = createRouteGuard();
|
||||
await guard.enforce({ pathname });
|
||||
|
||||
return (
|
||||
<AuthGuard redirectPath="/auth/login">
|
||||
<div className="min-h-screen bg-deep-graphite">
|
||||
{children}
|
||||
</div>
|
||||
</AuthGuard>
|
||||
<div className="min-h-screen bg-deep-graphite">
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export default function SponsorPage() {
|
||||
// Server-side redirect to sponsor dashboard
|
||||
redirect('/sponsor/dashboard');
|
||||
}
|
||||
@@ -174,9 +174,10 @@ export default function SponsorSettingsPage() {
|
||||
|
||||
const handleDeleteAccount = () => {
|
||||
if (confirm('Are you sure you want to delete your sponsor account? This action cannot be undone. All sponsorship data will be permanently removed.')) {
|
||||
document.cookie = 'gridpilot_demo_mode=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
||||
document.cookie = 'gridpilot_sponsor_id=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT';
|
||||
router.push('/');
|
||||
// Call logout API to clear session
|
||||
fetch('/api/auth/logout', { method: 'POST' }).finally(() => {
|
||||
router.push('/');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -143,10 +143,21 @@ export default function SponsorSignupPage() {
|
||||
const handleDemoLogin = async () => {
|
||||
setSubmitting(true);
|
||||
try {
|
||||
document.cookie = 'gridpilot_demo_mode=sponsor; path=/; max-age=86400';
|
||||
document.cookie = 'gridpilot_sponsor_id=demo-sponsor-1; path=/; max-age=86400';
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
// Use the demo login API instead of setting cookies
|
||||
const response = await fetch('/api/auth/demo-login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ role: 'sponsor' }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Demo login failed');
|
||||
}
|
||||
|
||||
router.push('/sponsor/dashboard');
|
||||
} catch (error) {
|
||||
console.error('Demo login failed:', error);
|
||||
alert('Demo login failed. Please check the API server status.');
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -195,11 +206,18 @@ export default function SponsorSignupPage() {
|
||||
setSubmitting(true);
|
||||
|
||||
try {
|
||||
// Demo: set cookies for sponsor mode
|
||||
document.cookie = 'gridpilot_demo_mode=sponsor; path=/; max-age=86400';
|
||||
document.cookie = `gridpilot_sponsor_name=${encodeURIComponent(formData.companyName)}; path=/; max-age=86400`;
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 800));
|
||||
// For demo purposes, use the demo login API with sponsor role
|
||||
// In production, this would create a real sponsor account
|
||||
const response = await fetch('/api/auth/demo-login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ role: 'sponsor' }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Signup failed');
|
||||
}
|
||||
|
||||
router.push('/sponsor/dashboard');
|
||||
} catch (err) {
|
||||
console.error('Sponsor signup failed:', err);
|
||||
|
||||
Reference in New Issue
Block a user