-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move application structure to /app route
- Loading branch information
1 parent
12abb43
commit c4df4e9
Showing
14 changed files
with
80 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use client"; | ||
|
||
import { useSession } from "next-auth/react"; | ||
import { usePathname, redirect } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
import SplashScreen from "~/components/patterns/splash-screen"; | ||
|
||
const ProtectedRoutes = ({ children }: { children: React.ReactNode }) => { | ||
const { status } = useSession(); | ||
const pathname = usePathname(); | ||
|
||
useEffect(() => { | ||
const allowedUnauthenticatedPaths = ["/app/login", "/"]; | ||
|
||
if ( | ||
status !== "loading" && | ||
status !== "authenticated" && | ||
!allowedUnauthenticatedPaths.includes(pathname) | ||
) { | ||
redirect("/app/login"); | ||
} | ||
}, [status, pathname]); | ||
|
||
if (status === "loading" && pathname.includes("/app")) | ||
return <SplashScreen />; | ||
return <>{children}</>; | ||
}; | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return <ProtectedRoutes>{children}</ProtectedRoutes>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
|
||
import { redirect } from "next/navigation"; | ||
import { LoginScreen } from "~/components/patterns/login-screen"; | ||
import { getServerAuthSession } from "~/server/auth"; | ||
|
||
const LoginPage = async () => { | ||
const session = await getServerAuthSession(); | ||
|
||
if (session?.user) { | ||
redirect("/app/usage"); | ||
} | ||
|
||
return ( | ||
<div> | ||
<LoginScreen /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LoginPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters