-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
70 lines (67 loc) · 2.4 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
import NextAuth from "next-auth";
import authConfig from "@/auth.config";
export const {
handlers,
auth,
signIn,
signOut,
} = NextAuth({
pages: {
signIn: "/signin",
},
...authConfig,
});
// v2
// export const {
// handlers,
// auth,
// signIn,
// signOut,
// } = NextAuth({
// adapter: PrismaAdapter(prismadb),
// callbacks: {
// async authorized ({request, auth}) {
// const ip = request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() || request.headers.get('x-real-ip') || request.ip || 'unknown';
// const blocklist = await fetchIpData();
// console.log(blocklist);
// if(blocklist && blocklist.includes(ip)) {request.cookies.clear(); return NextResponse.json({ error: "Too Many Requests. Contact Admin." }, { status: 429 });};
// // not blocked
// const isRateLimited = rateLimiter.limit(ip); // true when rate limit crossed
// if (isRateLimited) {
// const isBlocked = blockLimiter.limit(ip); // true when block limit crossed
// if(isBlocked) { await SubmitIpData(ip); } // revalidateTag('blocklist');
// if(!request.url.includes("/error/too-many-requests")) return NextResponse.redirect(new URL("/error/too-many-requests", request.nextUrl));
// };
// return true;
// },
// async jwt({ token }) {
// if(!token.sub) return token;
// const existingUser = await getUserById(token.sub);
// if(existingUser === false) {token.role = "null"; revalidateTag("user"); console.log("signed out in the auth config"); return token; } // user not found, see if automatically goes to signin
// if(existingUser === null) return token; // edge error null
// token.role = existingUser.role;
// return token;
// },
// async session({ token, session }) {
// if(token.sub && session.user) {
// session.user.id = token.sub;
// }
// if(token.role && session.user) {
// session.user.role = token.role as string;
// }
// return session;
// },
// async signIn(){
// revalidateTag("user");
// return true;
// },
// },
// session: {
// strategy: "jwt",
// maxAge: 60 * 60 * 60, // 1 day (6 hours)
// },
// pages: {
// signIn: "/signin",
// },
// ...authConfig,
// });