Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aryasaatvik committed Jul 25, 2024
1 parent 83f4b24 commit 3b5812c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
9 changes: 1 addition & 8 deletions apps/web/app/(auth)/signin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import Image from "next/image";
import Link from "next/link";
import Logo from "@/public/logo.svg";
import { auth, signIn } from "@/server/auth";
import { signIn } from "@/server/auth";
import { Google } from "@repo/ui/components/icons";
import gradientStyle from "./_components/TextGradient/gradient.module.css";
import { cn } from "@repo/ui/lib/utils";
import { redirect } from "next/navigation";

export const runtime = "edge";

async function Signin() {
const user = await auth();

if (user) {
redirect("/home");
}

return (
<div className="flex relative font-geistSans overflow-hidden items-center justify-between min-h-screen">
<div className="relative w-full lg:w-1/2 flex items-center min-h-screen bg-page-gradient p-8 border-r-[1px] border-white/5">
Expand Down
4 changes: 3 additions & 1 deletion apps/web/app/(dash)/header/signOutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export default function SignOutButton() {
<form
action={async () => {
"use server"
await signOut()
await signOut({
redirectTo: "/",
});
}}
>
<Button variant="ghost" size="sm" type="submit" className="text-[#7D8994]">
Expand Down
8 changes: 0 additions & 8 deletions apps/web/app/(landing)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@ import Cta from "./Cta";
import { Toaster } from "@repo/ui/shadcn/toaster";
import Features from "./Features";
import Footer from "./footer";
import { auth } from "@/server/auth";
import Services from "./Features/index";
import { Showcases } from "./Showcase";
import BackgroundPlus from "./GridPatterns/PlusGrid";
import { redirect } from "next/navigation";

export const runtime = "edge";

export default async function Home() {
const user = await auth();

if (user) {
redirect("/home");
}

return (
<>
<BackgroundPlus />
Expand Down
15 changes: 11 additions & 4 deletions apps/web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@ export async function middleware(request: NextRequest) {
Object.entries(corsHeaders).forEach(([key, value]) => {
response.headers.set(key, value);
});

return response;
}
const info = await auth();
if (routeTypes.authed.some((route) => request.nextUrl.pathname.startsWith(route))) {
if (!info) {
NextResponse.redirect(new URL("/signin", request.nextUrl));
return NextResponse.redirect(new URL("/signin", request.nextUrl));
}
} else {
} else if (routeTypes.unAuthedOnly.some((route) => request.nextUrl.pathname.endsWith(route))) {
if (info) {
NextResponse.redirect(new URL("/home", request.nextUrl));
return NextResponse.redirect(new URL("/home", request.nextUrl));
}
}
return NextResponse.next();
}

export const config = {
matcher: [
'/((?!_next/static|_next/image|image|favicon.ico).*)',
'/api/:path*',
'/.:path*',
]
};
1 change: 1 addition & 0 deletions apps/web/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const routeGroups = {
export const routeTypes = {
authed: [...routeGroups.canvas, ...routeGroups.dash, ...routeGroups.other],
unauthed: [...routeGroups.auth, ...routeGroups.landing],
unAuthedOnly: [...routeGroups.landing, "/signin"],
}

0 comments on commit 3b5812c

Please sign in to comment.