Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-bach committed May 17, 2024
1 parent 47ca0be commit 3e8e17d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ X Add authentication middleware - https://www.youtube.com/watch?v=Y3o4or23V-0
X Style Auth pages
X Style verify email

- nextjs_template branch

- Add unprotected landing page without navbar/sidebar

- Add navbar - https://github.com/Siumauricio/nextui-dashboard-template?tab=readme-ov-file
- Sidebar improvements - https://github.com/Siumauricio/nextui-dashboard-template?tab=readme-ov-file
- Add manage profile
Expand Down
11 changes: 1 addition & 10 deletions frontend.template/src/app/auth/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import PecuniaryLogo from '@/components/pecuniary-logo';

export default function Layout({ children }: { children: React.ReactNode }) {
return (
<main className='flex items-center justify-center md:h-screen'>
<div className='relative mx-auto flex w-full max-w-[400px] flex-col space-y-2.5 p-4 md:-mt-32'>
{/* <div className='flex h-20 w-full items-end rounded-lg bg-blue-500 p-3 md:h-36'>
<div className='w-32 text-white md:w-36'>
<PecuniaryLogo />
</div>
</div> */}
{children}
</div>
<div className='relative mx-auto flex w-full max-w-[400px] flex-col space-y-2.5 p-4 md:-mt-32'>{children}</div>
</main>
);
}
6 changes: 4 additions & 2 deletions frontend.template/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export default function RootLayout({ children }: { children: React.ReactNode })
return (
<html lang='en'>
<body className={clsx('font-sans antialiased', fontSans.className)}>
<ConfigureAmplifyClientSide />
<Providers>{children}</Providers>
<Providers>
<ConfigureAmplifyClientSide />
{children}
</Providers>
</body>
</html>
);
Expand Down
12 changes: 6 additions & 6 deletions frontend.template/src/components/layout/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import { useLockedBody } from "../hooks/useBodyLock";
import { NavbarWrapper } from "../navbar/navbar";
import { SidebarWrapper } from "../sidebar/sidebar";
import { SidebarContext } from "./layout-context";
import React from 'react';
import { useLockedBody } from '../hooks/useBodyLock';
import { NavbarWrapper } from '../navbar/navbar';
import { SidebarWrapper } from '../sidebar/sidebar';
import { SidebarContext } from './layout-context';

interface Props {
children: React.ReactNode;
Expand All @@ -23,7 +23,7 @@ export const Layout = ({ children }: Props) => {
setCollapsed: handleToggleSidebar,
}}
>
<section className="flex">
<section className='flex'>
<SidebarWrapper />
<NavbarWrapper>{children}</NavbarWrapper>
</section>
Expand Down
23 changes: 15 additions & 8 deletions frontend.template/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@ export async function middleware(request: NextRequest) {
const response = NextResponse.next();
const user = await authenticatedUser({ request, response });

const isOnDashboard = request.nextUrl.pathname.startsWith('/dashboard');
const isOnAdminArea = request.nextUrl.pathname.startsWith('/dashboard/admin');
const protectedRoutes = ['/dashboard', '/dashboard/admin', '/accounts'];

if (isOnDashboard) {
if (!user) return NextResponse.redirect(new URL('/auth/login', request.nextUrl));
if (isOnAdminArea && !user.isAdmin) return NextResponse.redirect(new URL('/dashboard', request.nextUrl));
return response;
} else if (user) {
return NextResponse.redirect(new URL('/dashboard', request.nextUrl));
if (!user && protectedRoutes.includes(request.nextUrl.pathname)) {
return NextResponse.redirect(new URL('/auth/login', request.nextUrl.origin));
}

// const isOnHome = request.nextUrl.pathname === '/' && !request.nextUrl.pathname.startsWith('/auth');
// const isOnDashboard = request.nextUrl.pathname.startsWith('/dashboard');
// const isOnAdminArea = request.nextUrl.pathname.startsWith('/dashboard/admin');

// if (isOnDashboard) {
// if (!user) return NextResponse.redirect(new URL('/auth/login', request.nextUrl));
// if (isOnAdminArea && !user.isAdmin) return NextResponse.redirect(new URL('/dashboard', request.nextUrl));
// return response;
// } else if (user) {
// return NextResponse.redirect(new URL('/dashboard', request.nextUrl));
// }
}

export const config = {
Expand Down

0 comments on commit 3e8e17d

Please sign in to comment.