mirror of
https://github.com/SrIzan10/stack.git
synced 2026-06-06 01:06:54 +00:00
feat: better protected routes, move to login, env example file
This commit is contained in:
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
||||
# from the dev postgres containeer
|
||||
DATABASE_URL=postgresql://postgres:dfsjhkdswkjntelsmldbfvsgknl5t@localhost:5555/postgres
|
||||
10
src/app/(protected)/layout.tsx
Normal file
10
src/app/(protected)/layout.tsx
Normal file
@@ -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
|
||||
}
|
||||
@@ -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 (
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold text-center">Welcome {user?.username}!</h1>
|
||||
<p>You are actually on a protected route!</p>
|
||||
<p>Your ID is: {user.id}</p>
|
||||
<p>Your ID is: {user!.id}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -34,7 +34,7 @@ export default function Page() {
|
||||
<SubmitButton buttonText="Create account" className="w-full" />
|
||||
<div className="text-center text-sm">
|
||||
Already have an account?
|
||||
<Link className="underline pl-1" href="/auth/signIn">
|
||||
<Link className="underline pl-1" href="/auth/login">
|
||||
Login
|
||||
</Link>
|
||||
</div>
|
||||
@@ -73,7 +73,7 @@ export default function Navbar() {
|
||||
</DropdownMenu>
|
||||
</>
|
||||
) : (
|
||||
<Link href="/auth/signIn">
|
||||
<Link href="/auth/login">
|
||||
<Button variant="outline">Sign in</Button>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user