File tree 9 files changed +429
-80
lines changed
9 files changed +429
-80
lines changed Original file line number Diff line number Diff line change 1
1
DATABASE_URL = " postgresql://postgres:example@localhost:5432/postgres"
2
2
3
3
# Next Auth Discord Provider
4
- GITHUB_CLIENT_ID = " "
5
- GITHUB_CLIENT_SECRET = " "
4
+ GITHUB_CLIENT_ID = " 63b03dd1a029181eede8 "
5
+ GITHUB_CLIENT_SECRET = " fe61fec0056b571d01d0a1e25945904237d164e8 "
6
6
7
7
NEXTAUTH_SECRET = " my_ultra_secure_nextauth_secret"
8
8
NEXTAUTH_URL = " http://localhost:3000"
Original file line number Diff line number Diff line change 1
1
version : " 3.9"
2
2
services :
3
- bg -db :
3
+ code-racer -db :
4
4
image : postgres
5
5
restart : always
6
6
container_name : code-racer-postgres
Original file line number Diff line number Diff line change 9
9
"lint" : " next lint"
10
10
},
11
11
"dependencies" : {
12
+ "@auth/prisma-adapter" : " ^1.0.0" ,
13
+ "@next-auth/prisma-adapter" : " ^1.0.7" ,
12
14
"@prisma/client" : " ^4.16.2" ,
13
15
"@radix-ui/react-slot" : " ^1.0.2" ,
14
- "@types/node" : " 20.4.1" ,
15
- "@types/react" : " 18.2.14" ,
16
- "@types/react-dom" : " 18.2.6" ,
17
16
"autoprefixer" : " 10.4.14" ,
18
17
"class-variance-authority" : " ^0.6.1" ,
19
18
"clsx" : " ^1.2.1" ,
20
- "eslint" : " 8.44.0" ,
21
- "eslint-config-next" : " 13.4.9" ,
22
19
"lucide-react" : " ^0.259.0" ,
23
20
"next" : " 13.4.9" ,
24
21
"next-auth" : " ^4.22.1" ,
31
28
"typescript" : " 5.1.6"
32
29
},
33
30
"devDependencies" : {
34
- "prisma" : " ^4.16.2"
31
+ "prisma" : " ^4.16.2" ,
32
+ "@types/node" : " 20.4.1" ,
33
+ "@types/react" : " 18.2.14" ,
34
+ "@types/react-dom" : " 18.2.6" ,
35
+ "eslint" : " 8.44.0" ,
36
+ "eslint-config-next" : " 13.4.9"
35
37
}
36
38
}
Original file line number Diff line number Diff line change @@ -8,7 +8,47 @@ datasource db {
8
8
}
9
9
10
10
model User {
11
- id Int @id @default (autoincrement () )
12
- createdAt DateTime @default (now () )
13
- name String ?
11
+ id String @id @default (cuid () )
12
+ createdAt DateTime @default (now () )
13
+ name String ?
14
+ email String ? @unique
15
+ emailVerified DateTime ?
16
+ image String ?
17
+ accounts Account []
18
+ sessions Session []
19
+ }
20
+
21
+ // Necessary for Next auth
22
+ model Account {
23
+ id String @id @default (cuid () )
24
+ userId String
25
+ type String
26
+ provider String
27
+ providerAccountId String
28
+ refresh_token String ? @db.Text
29
+ access_token String ? @db.Text
30
+ expires_at Int ?
31
+ token_type String ?
32
+ scope String ?
33
+ id_token String ? @db.Text
34
+ session_state String ?
35
+ user User @relation (fields : [userId ] , references : [id ] , onDelete : Cascade )
36
+
37
+ @@unique ([provider , providerAccountId ] )
38
+ }
39
+
40
+ model Session {
41
+ id String @id @default (cuid () )
42
+ sessionToken String @unique
43
+ userId String
44
+ expires DateTime
45
+ user User @relation (fields : [userId ] , references : [id ] , onDelete : Cascade )
46
+ }
47
+
48
+ model VerificationToken {
49
+ identifier String
50
+ token String @unique
51
+ expires DateTime
52
+
53
+ @@unique ([identifier , token ] )
14
54
}
Original file line number Diff line number Diff line change
1
+ import { prisma } from "@/lib/prisma" ;
2
+ import { PrismaAdapter } from "@next-auth/prisma-adapter" ;
1
3
import NextAuth from "next-auth" ;
2
4
import GithubProvider from "next-auth/providers/github" ;
3
5
4
- const handler = NextAuth ( {
6
+ export const nextAuthOptions = {
7
+ adapter : PrismaAdapter ( prisma ) ,
5
8
providers : [
6
9
GithubProvider ( {
7
10
clientId : process . env . GITHUB_CLIENT_ID ! ,
8
11
clientSecret : process . env . GITHUB_CLIENT_SECRET ! ,
9
12
} ) ,
10
13
] ,
11
- } ) ;
14
+ } ;
15
+
16
+ const handler = NextAuth ( nextAuthOptions ) ;
12
17
13
18
export { handler as GET , handler as POST } ;
Original file line number Diff line number Diff line change 1
1
import { Button } from "@/components/ui/button" ;
2
2
import { LoginButton , LogoutButton } from "@/components/ui/buttons" ;
3
+ import { getSession } from "@/lib/getSession" ;
3
4
import { prisma } from "@/lib/prisma" ;
4
- import { getServerSession } from "next-auth" ;
5
5
import Image from "next/image" ;
6
6
7
7
export default async function Home ( ) {
8
- const users = await prisma . user . findMany ( ) ;
9
- console . log ( users ) ;
10
- const session = await getServerSession ( ) ;
11
- return (
12
- < main className = "flex min-h-screen flex-col items-center justify-between p-24" >
13
- < Button > Button</ Button >
14
- { session ? (
15
- < div className = "flex space-x-2 items-center" >
16
- < Image
17
- className = "rounded-full"
18
- src = { session ?. user ?. image ! }
19
- alt = "user avatar"
20
- height = { 40 }
21
- width = { 40 }
22
- />
23
- < p className = "text-gray-700 font-bold" >
24
- { session ?. user ?. name }
25
- </ p >
26
- < LogoutButton />
27
- </ div >
28
- ) : (
29
- < LoginButton />
30
- ) }
31
- </ main >
32
- ) ;
8
+ const users = await prisma . user . findMany ( ) ;
9
+ const session = await getSession ( ) ;
10
+
11
+ return (
12
+ < main className = "flex min-h-screen flex-col items-center justify-between p-24" >
13
+ < Button > Button</ Button >
14
+ { session ? (
15
+ < div className = "flex space-x-2 items-center" >
16
+ < Image
17
+ className = "rounded-full"
18
+ src = { session ?. user ?. image ! }
19
+ alt = "user avatar"
20
+ height = { 40 }
21
+ width = { 40 }
22
+ />
23
+ < p className = "text-gray-700 font-bold" > { session ?. user ?. name } </ p >
24
+ < LogoutButton />
25
+ </ div >
26
+ ) : (
27
+ < LoginButton />
28
+ ) }
29
+ </ main >
30
+ ) ;
33
31
}
Original file line number Diff line number Diff line change
1
+ import { nextAuthOptions } from "@/app/api/auth/[...nextauth]/route" ;
2
+ import { getServerSession } from "next-auth" ;
3
+
4
+ export function getSession ( ) {
5
+ return getServerSession ( nextAuthOptions ) ;
6
+ }
Original file line number Diff line number Diff line change 1
- import { PrismaClient } from ' @prisma/client'
1
+ import { PrismaClient } from " @prisma/client" ;
2
2
3
3
const globalForPrisma = globalThis as unknown as {
4
- prisma : PrismaClient | undefined
5
- }
4
+ prisma : PrismaClient | undefined ;
5
+ } ;
6
6
7
- export const prisma = globalForPrisma . prisma ?? new PrismaClient ( )
7
+ export const prisma = globalForPrisma . prisma ?? new PrismaClient ( ) ;
8
8
9
- if ( process . env . NODE_ENV !== ' production' ) globalForPrisma . prisma = prisma
9
+ if ( process . env . NODE_ENV !== " production" ) globalForPrisma . prisma = prisma ;
You can’t perform that action at this time.
0 commit comments