mirror of
https://github.com/trafficlunar/tomodachi-share.git
synced 2026-05-13 13:17:45 +00:00
32 lines
1,005 B
TypeScript
32 lines
1,005 B
TypeScript
import NextAuth from "next-auth";
|
|
import Discord from "next-auth/providers/discord";
|
|
import Github from "next-auth/providers/github";
|
|
import Google from "next-auth/providers/google";
|
|
|
|
import { PrismaAdapter } from "@auth/prisma-adapter";
|
|
import { prisma } from "@/lib/prisma";
|
|
|
|
export const { handlers, signIn, signOut, auth } = NextAuth({
|
|
adapter: PrismaAdapter(prisma),
|
|
providers: [Discord, Github({ issuer: "https://github.com/login/oauth" }), Google],
|
|
pages: {
|
|
signIn: "/login",
|
|
},
|
|
callbacks: {
|
|
async signIn({ user }) {
|
|
const blacklist = process.env.BLACKLISTED_EMAILS ? process.env.BLACKLISTED_EMAILS.split(",").map((item) => item.trim().toLowerCase()) : [];
|
|
const email = user?.email?.toLowerCase();
|
|
if (!email) return false;
|
|
if (blacklist?.some((blocked) => email.endsWith(blocked))) return false;
|
|
return true;
|
|
},
|
|
|
|
async session({ session, user }) {
|
|
if (user) {
|
|
session.user.id = user.id;
|
|
session.user.email = user.email;
|
|
}
|
|
return session;
|
|
},
|
|
},
|
|
});
|