-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
216 lines (180 loc) · 5.91 KB
/
auth.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// import NextAuth from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import bcrypt from 'bcrypt';
import { sql } from '@vercel/postgres';
import { z } from 'zod';
import type { User } from '@/app/lib/definitions';
//import { authConfig } from './auth.config';
async function getUser(email: string): Promise<User | undefined> {
try {
const user = await sql<User>`SELECT * FROM users WHERE email=${email}`;
return user.rows[0];
} catch (error) {
console.error('Failed to fetch user:', error);
throw new Error('Failed to fetch user.');
}
}
// export const { auth, signIn, signOut } = NextAuth({
// providers: [
// Credentials({
// async authorize(credentials) {
// const parsedCredentials = z
// .object({ email: z.string().email(), password: z.string().min(6) })
// .safeParse(credentials);
// if (parsedCredentials.success) {
// const { email, password } = parsedCredentials.data;
// const user = await getUser(email);
// if (!user) return null;
// const passwordsMatch = await bcrypt.compare(password, user.password);
// if (passwordsMatch) return user;
// }
// console.log('Invalid credentials');
// return null;
// },
// }),
// ],
// });
import NextAuth from "next-auth"
import Apple from "next-auth/providers/apple"
// import Auth0 from "next-auth/providers/auth0"
// import AzureB2C from "next-auth/providers/azure-ad-b2c"
// import BoxyHQSAML from "next-auth/providers/boxyhq-saml"
// import Cognito from "next-auth/providers/cognito"
import Coinbase from "next-auth/providers/coinbase"
import Discord from "next-auth/providers/discord"
// import Dropbox from "next-auth/providers/dropbox"
// import Facebook from "next-auth/providers/facebook"
import GitHub from "next-auth/providers/github"
// import Gitlab from "next-auth/providers/gitlab"
import Google from "next-auth/providers/google"
// import Hubspot from "next-auth/providers/hubspot"
// import Keycloak from "next-auth/providers/keycloak"
// import LinkedIn from "next-auth/providers/linkedin"
// import Netlify from "next-auth/providers/netlify"
// import Okta from "next-auth/providers/okta"
// import Passage from "next-auth/providers/passage"
// import Pinterest from "next-auth/providers/pinterest"
// import Reddit from "next-auth/providers/reddit"
// import Slack from "next-auth/providers/slack"
// import Spotify from "next-auth/providers/spotify"
// import Twitch from "next-auth/providers/twitch"
import Twitter from "next-auth/providers/twitter"
// import WorkOS from "next-auth/providers/workos"
// import Zoom from "next-auth/providers/zoom"
import type { NextAuthConfig } from "next-auth"
import AcmeLogo from '@/app/ui/acme-logo';
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
export const config = {
theme: { logo: "https://authjs.dev/img/logo-sm.png" },
// theme: { logo: AcmeLogo },
// cookies: {
// pkceCodeVerifier: {
// name: "next-auth.pkce.code_verifier",
// options: {
// httpOnly: true,
// sameSite: "none",
// path: "/dashboard",
// secure: true,
// },
// },
// },
// pkceCodeVerifier: {
// name: 'next-auth.pkce.code_verifier',
// options: {
// httpOnly: true,
// sameSite: 'none',
// path: '/',
// secure: process.env.NODE_ENV === 'production',
// },
// },
// https://github.com/nextauthjs/next-auth/discussions/6898#discussioncomment-5308820
// cookies: {
// pkceCodeVerifier: {
// name: "next-auth.pkce.code_verifier",
// options: {
// httpOnly: true,
// sameSite: "none",
// path: "/",
// secure: true,
// },
// },
// },
adapter: PrismaAdapter(prisma),
providers: [
// Auth0,
// AzureB2C({
// clientId: process.env.AUTH_AZURE_AD_B2C_ID,
// clientSecret: process.env.AUTH_AZURE_AD_B2C_SECRET,
// issuer: process.env.AUTH_AZURE_AD_B2C_ISSUER,
// }),
// BoxyHQSAML({
// clientId: "dummy",
// clientSecret: "dummy",
// issuer: process.env.AUTH_BOXYHQ_SAML_ISSUER,
// }),
// Cognito,
// Dropbox,
// Facebook,
// Gitlab,
// Hubspot,
// Keycloak,
// LinkedIn,
// Netlify,
// Okta,
// Passage,
// Pinterest,
// Reddit,
// Slack,
// Spotify,
// Twitch,
// WorkOS({
// connection: process.env.AUTH_WORKOS_CONNECTION,
// }),
// Zoom,
GitHub({
checks:["none"]
}),
Twitter,
// Twitter({
// clientId: process.env.TWITTER_ID,
// clientSecret: process.env.TWITTER_SECRET,
// //version: "2.0", // opt-in to Twitter OAuth 2.0
// })
// Twitter({
// // clientId: process.env.AUTH_TWITTER_ID,
// // clientSecret: process.env.AUTH_TWITTER_SECRET,
// //version: "2.0", // opt-in to Twitter OAuth 2.0
// // clientId: "dummy",
// // clientSecret: "dummy",
// // issuer: process.env.AUTH_BOXYHQ_SAML_ISSUER,
// }),
// Google,
// Discord,
// Coinbase,
// Apple,
],
basePath: "/auth",
callbacks: {
authorized({ request, auth }) {
const { pathname } = request.nextUrl
if (pathname === "/middleware-example") return !!auth
return true
},
jwt({ token, trigger, session }) {
if (trigger === "update") token.name = session.user.name
return token
},
},
} satisfies NextAuthConfig
export const { handlers, auth, signIn, signOut } = NextAuth(config)
// import Passkey from "next-auth/providers/passkey"
// import { PrismaAdapter } from "@auth/prisma-adapter"
// import { PrismaClient } from "@prisma/client"
// const prisma = new PrismaClient()
// export default {
// adapter: PrismaAdapter(prisma),
// providers: [Passkey],
// experimental: { enableWebAuthn: true },
// }