~repos /edge-city
git clone https://pyrossh.dev/repos/edge-city.git
edge-city is a next level meta-framework for react that runs only on edge runtimes
ca092062
—
Peter John 2 years ago
add next-auth
packages/example/bun.lockb
CHANGED
|
Binary file
|
packages/example/db/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { migrate } from 'drizzle-orm/neon-serverless/migrator';
|
|
|
5
5
|
import { highlight } from 'sql-highlight';
|
|
6
6
|
|
|
7
7
|
export const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
8
|
-
|
|
8
|
+
const db = drizzle(pool, {
|
|
9
9
|
logger: {
|
|
10
10
|
logQuery: (query, params) => {
|
|
11
11
|
const sqlString = params.reduce((acc, v, i) => acc.replaceAll("$" + (i + 1), v), query);
|
|
@@ -14,6 +14,8 @@ export const db = drizzle(pool, {
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
+
export default db;
|
|
18
|
+
|
|
17
19
|
export const migrateAll = async () => {
|
|
18
20
|
await migrate(db, { migrationsFolder: './db/migrations' });
|
|
19
21
|
}
|
|
@@ -24,4 +26,4 @@ export const todos = pgTable('todos', {
|
|
|
24
26
|
completed: boolean('completed').notNull(),
|
|
25
27
|
createdAt: date('createdAt').notNull(),
|
|
26
28
|
updatedAt: date('updatedAt'),
|
|
27
|
-
});
|
|
29
|
+
});
|
packages/example/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@neondatabase/serverless": "^0.2.9",
|
|
14
|
+
"drizzle-auth-adaptor-pg": "^0.0.3",
|
|
14
15
|
"drizzle-orm": "0.25.4",
|
|
15
16
|
"next-auth": "^4.22.1",
|
|
16
17
|
"react": "18.2.0",
|
packages/example/routes/api/auth/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import NextAuth from "next-auth";
|
|
2
|
+
import EmailProvider from "next-auth/providers/email";
|
|
3
|
+
import GoogleProvider from "next-auth/providers/google";
|
|
4
|
+
import DrizzleAuthAdapterPG from "drizzle-auth-adaptor-pg";
|
|
5
|
+
import db from "@/db";
|
|
6
|
+
|
|
7
|
+
// GET /api/auth/signin
|
|
8
|
+
// POST /api/auth/signin/:provider
|
|
9
|
+
// GET/POST /api/auth/callback/:provider
|
|
10
|
+
// GET /api/auth/signout
|
|
11
|
+
// POST /api/auth/signout
|
|
12
|
+
// GET /api/auth/session
|
|
13
|
+
// GET /api/auth/csrf
|
|
14
|
+
// GET /api/auth/providers
|
|
15
|
+
|
|
16
|
+
// NEXTAUTH_SECRET="This is an example"
|
|
17
|
+
// NEXTAUTH_URL
|
|
18
|
+
|
|
19
|
+
// import { SessionProvider } from "next-auth/react"
|
|
20
|
+
// export default function App({
|
|
21
|
+
// Component,
|
|
22
|
+
// pageProps: { session, ...pageProps },
|
|
23
|
+
// }) {
|
|
24
|
+
// return (
|
|
25
|
+
// <SessionProvider session={session}>
|
|
26
|
+
// <Component {...pageProps} />
|
|
27
|
+
// </SessionProvider>
|
|
28
|
+
// )
|
|
29
|
+
// }
|
|
30
|
+
|
|
31
|
+
const handler = NextAuth({
|
|
32
|
+
adapter: DrizzleAuthAdapterPG(db),
|
|
33
|
+
providers: [
|
|
34
|
+
EmailProvider({
|
|
35
|
+
server: {
|
|
36
|
+
host: process.env.SMTP_HOST,
|
|
37
|
+
port: Number(process.env.SMTP_PORT),
|
|
38
|
+
auth: {
|
|
39
|
+
user: process.env.SMTP_USER,
|
|
40
|
+
pass: process.env.SMTP_PASSWORD,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
from: process.env.EMAIL_FROM,
|
|
44
|
+
}),
|
|
45
|
+
GoogleProvider({
|
|
46
|
+
clientId: process.env.GOOGLE_CLIENT_ID,
|
|
47
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const onGet = handler
|
|
53
|
+
|
|
54
|
+
export const onPost = handler
|
packages/example/routes/api/todos/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { gt, eq } from 'drizzle-orm';
|
|
2
|
-
import
|
|
2
|
+
import db, { todos } from "@/db";
|
|
3
3
|
|
|
4
4
|
export const onGet = async (req) => {
|
|
5
5
|
const url = new URL(req.url);
|