diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f79672a --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +# from the dev postgres containeer +DATABASE_URL=postgresql://postgres:dfsjhkdswkjntelsmldbfvsgknl5t@localhost:5555/postgres \ No newline at end of file diff --git a/src/app/(protected)/layout.tsx b/src/app/(protected)/layout.tsx new file mode 100644 index 0000000..ff22080 --- /dev/null +++ b/src/app/(protected)/layout.tsx @@ -0,0 +1,10 @@ +import { validateRequest } from "@/lib/auth"; +import { redirect } from "next/navigation"; + +export default async function Layout({ children }: { children: React.ReactNode }) { + const { user } = await validateRequest() + if (!user) { + return redirect('/auth/login') + } + return children +} \ No newline at end of file diff --git a/src/app/protected/page.tsx b/src/app/(protected)/protected/page.tsx similarity index 71% rename from src/app/protected/page.tsx rename to src/app/(protected)/protected/page.tsx index 9f777f2..575648b 100644 --- a/src/app/protected/page.tsx +++ b/src/app/(protected)/protected/page.tsx @@ -1,14 +1,12 @@ import { validateRequest } from "@/lib/auth"; -import { redirect } from "next/navigation"; export default async function Page() { const { user } = await validateRequest() - if (!user) return redirect('/auth/signIn') return (

Welcome {user?.username}!

You are actually on a protected route!

-

Your ID is: {user.id}

+

Your ID is: {user!.id}

) } \ No newline at end of file diff --git a/src/app/auth/signIn/page.tsx b/src/app/(public)/auth/login/page.tsx similarity index 100% rename from src/app/auth/signIn/page.tsx rename to src/app/(public)/auth/login/page.tsx diff --git a/src/app/auth/signUp/page.tsx b/src/app/(public)/auth/signUp/page.tsx similarity index 95% rename from src/app/auth/signUp/page.tsx rename to src/app/(public)/auth/signUp/page.tsx index 7eb8a79..a59c3e9 100644 --- a/src/app/auth/signUp/page.tsx +++ b/src/app/(public)/auth/signUp/page.tsx @@ -34,7 +34,7 @@ export default function Page() {
Already have an account? - + Login
diff --git a/src/app/page.tsx b/src/app/(public)/page.tsx similarity index 100% rename from src/app/page.tsx rename to src/app/(public)/page.tsx diff --git a/src/components/app/NavBar/NavBar.tsx b/src/components/app/NavBar/NavBar.tsx index b9808ea..299003b 100644 --- a/src/components/app/NavBar/NavBar.tsx +++ b/src/components/app/NavBar/NavBar.tsx @@ -73,7 +73,7 @@ export default function Navbar() { ) : ( - + )} diff --git a/src/lib/auth/actions.ts b/src/lib/auth/actions.ts index 82c9e78..87bcb07 100644 --- a/src/lib/auth/actions.ts +++ b/src/lib/auth/actions.ts @@ -13,7 +13,7 @@ export async function logout() { await lucia.invalidateSession(session!.id); const sessionCookie = lucia.createBlankSessionCookie(); cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes); - return redirect("/auth/signIn"); + return redirect("/auth/login"); } export async function login(prev: any, data: FormData) {