comicbox/pages/api/auth/[...nextauth].ts

45 lines
1.4 KiB
TypeScript

import NextAuth, { NextAuthOptions } from 'next-auth';
import Keycloak from 'next-auth/providers/keycloak';
import Discord from 'next-auth/providers/discord';
import GitHub from 'next-auth/providers/github';
import process from 'process';
import { PrismaAdapter } from '@next-auth/prisma-adapter';
import { prisma } from '../../../src/db';
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
Keycloak({
clientId: process.env.KEYCLOAK_ID!,
clientSecret: process.env.KEYCLOAK_SECRET!,
issuer: process.env.KEYCLOAK_ISSUER!,
}),
Discord({
clientId: process.env.DISCORD_CLIENT_ID!,
clientSecret: process.env.DISCORD_CLIENT_SECRET!,
authorization:
'https://discord.com/api/oauth2/authorize?scope=identify',
}),
GitHub({
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
}),
],
callbacks: {
signIn(params) {
params.account['not-before-policy'] = undefined;
return true;
},
session(params) {
if (params.session.user) {
params.session.user.id = params.user.id;
}
return params.session;
},
},
pages: {
signIn: '/login',
},
};
export default NextAuth(authOptions);