Skip to content

Commit 33e7ce3

Browse files
committed
Handle Redirect to Root Folder
1 parent 225ab05 commit 33e7ce3

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/app/drive/page.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
export default function DrivePage() {
2-
return <div />;
1+
import { auth } from "@clerk/nextjs/server";
2+
import { redirect } from "next/navigation";
3+
4+
import * as queries from "~/server/db/queries";
5+
6+
export default async function DrivePage() {
7+
const session = await auth();
8+
if (!session.userId) return redirect("/sign-in");
9+
10+
const rootFolder = await queries.getRootFolderForUser(session.userId);
11+
if (!rootFolder) return redirect("/drive/create-root-folder");
12+
13+
return redirect(`/f/${rootFolder.id}`);
314
}

src/app/sign-in/page.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { SignInButton } from "@clerk/nextjs";
22

3+
import { Button } from "~/components/ui/button";
4+
35
export default function HomePage() {
46
return (
57
<div className="min-h-screen bg-gradient-to-br from-black via-gray-900 to-gray-800 text-white">
@@ -18,7 +20,14 @@ export default function HomePage() {
1820
documents from any device, anywhere in the world.
1921
</p>
2022

21-
<SignInButton />
23+
<Button
24+
size="lg"
25+
className="cursor-pointer rounded-full bg-white px-8 py-6 text-lg font-semibold text-black transition-all duration-200 hover:scale-105 hover:bg-gray-100"
26+
type="submit"
27+
asChild
28+
>
29+
<SignInButton forceRedirectUrl="/drive" />
30+
</Button>
2231
</div>
2332
</main>
2433
</div>

src/server/db/queries.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "server-only"; // Ensure this file is only run on the server
22

3-
import { eq } from "drizzle-orm";
3+
import { and, eq, isNull } from "drizzle-orm";
44

55
import { db } from "~/server/db";
66
import {
@@ -27,6 +27,14 @@ export async function getAllParentsForFolder(folderId: number) {
2727
return parents;
2828
}
2929

30+
export async function getRootFolderForUser(ownerId: string) {
31+
const folders = await db
32+
.select()
33+
.from(folderSchema)
34+
.where(and(eq(folderSchema.ownerId, ownerId), isNull(folderSchema.parent)));
35+
return folders[0];
36+
}
37+
3038
export function getAllFolders(folderId: number) {
3139
return db
3240
.select()

0 commit comments

Comments
 (0)