-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.js
More file actions
60 lines (55 loc) · 1.34 KB
/
auth.js
File metadata and controls
60 lines (55 loc) · 1.34 KB
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
import NextAuth from "next-auth";
import authConfig from "@/auth.config";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "@/lib/prisma";
const paths = [
"/create",
"/edit",
"/my-bots",
"/view"
]
export const { handlers, signIn, signOut, newUser, auth } = NextAuth({
debug: !!process.env.AUTH_DEBUG,
adapter: PrismaAdapter(prisma),
session: {
maxAge: 60 * 60,
strategy: "jwt",
},
callbacks: {
authorized({ request, auth }) {
const { pathname } = request.nextUrl
if (paths.find((p) => p == pathname)) return !!auth
return true
},
jwt({ token, trigger, user, account }) {
if (trigger === "update") token.name = session.user.username;
// if (account?.provider === "credentials") {
// token.credentials = true;
// }
if (user) {
// User is available during sign-in
// token.id = user.id;
token.name = user.username;
}
return token;
},
session({ session, token }) {
// if (token?.id) session.id = token.id;
// if (token?.name) session.name = token.name;
return session;
},
},
credentials: {
username: {},
password: {},
},
jwt: {
secret: process.env.NEXTAUTH_SECRET,
},
pages: {
error: "/error",
newUser: "/signup",
signIn: "/login",
},
...authConfig,
});