从零搭建基于 AI GitHub 分析平台 (7) Create Project API

设置 Authenticated Route

修改 src/server/api/trpc.ts:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const isAuthenticated = t.middleware(async ({ next, ctx }) => {
const user = await auth();
if(!user){
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You must be logged in to perform this action",
});
};

return next({
ctx : {
...ctx,
user
}
});
});

export const authenticatedProcedure = publicProcedure.use(isAuthenticated);
More...

从零搭建基于 AI GitHub 分析平台 (4) 搭建Layout

搭建Layout框架

添加 src/app/(protected)/layout.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { SidebarProvider } from "@/components/ui/sidebar";
import { UserButton } from "@clerk/nextjs";
import React from "react";


type Props = {
children: React.ReactNode
}

const SidebarLayout = ( {children} : Props ) => {
return (
<SidebarProvider>
{/* <AppSiderbar /> */}
<main className="w-full m-2">
{/* top bar */}
<div className="flex items-center gap-2 border-siderbar-border bg-sidebar border shadow rounded-md p-2 px-4">
{/* <SearchBar /> */}
<div className="ml-auto"></div>
<UserButton />
</div>
<div className="h-4"></div>
{/* main content */}
<div className="border-sidebar-border bg-sidebar border shadow rounded-md overflow-y-auto h-[calc(100vh-6rem)] p-4">
{children}
</div>
</main>
</SidebarProvider>
)
}

export default SidebarLayout;
More...

从零搭建基于 AI GitHub 分析平台 (3) 同步 Clerk 用户数据

修改数据结构

修改 prisma/schema.prisma

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

firstName String?
lastName String?
imageUrl String?

emailAddress String @unique

credits Int @default(150)
}

运行命令,更新数据库:

1
bun prisma db push
More...

从零搭建基于 AI GitHub 分析平台 (1) 搭建框架

项目介绍

本次计划搭建一个基于AI的 Github 分析平台,根据搭建步骤会一一介绍。

创建NextJs项目

本次通过 T3 模版创建项目

1
bunx create-t3-app@latest

通过命令,创建 NextJs 项目 aigithub
下面是创建项目的选项:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
   ___ ___ ___   __ _____ ___   _____ ____    __   ___ ___
/ __| _ \ __| / \_ _| __| |_ _|__ / / \ | _ \ _ \
| (__| / _| / /\ \| | | _| | | |_ \ / /\ \| _/ _/
\___|_|_\___|_/‾‾\_\_| |___| |_| |___/ /_/‾‾\_\_| |_|

◇ What will your project be called?
│ aigithub

◇ Will you be using TypeScript or JavaScript?
│ TypeScript

◇ Will you be using Tailwind CSS for styling?
│ Yes

◇ Would you like to use tRPC?
│ Yes

◇ What authentication provider would you like to use?
│ None

◇ What database ORM would you like to use?
│ Prisma

◇ Would you like to use Next.js App Router?
│ Yes

◇ What database provider would you like to use?
│ PostgreSQL

◇ Should we initialize a Git repository and stage the changes?
│ Yes

◇ Should we run 'bun install' for you?
│ Yes

◇ What import alias would you like to use?
│ @
More...

请我喝杯咖啡吧~

支付宝
微信