1
0
mirror of https://github.com/tabler/tabler.git synced 2025-12-22 01:44:25 +04:00
Files
tabler/site/lib/auth.ts
tabler.developer@gmail.com 09a8e2d2c5 lemon squeezy integration
2023-12-07 00:56:02 +01:00

112 lines
2.9 KiB
TypeScript

import prisma from '@/lib/prisma'
import { PrismaAdapter } from '@next-auth/prisma-adapter'
import GitHubProvider from 'next-auth/providers/github'
import GoogleProvider from 'next-auth/providers/google'
import { NextAuthOptions } from 'next-auth'
import Auth0Provider from 'next-auth/providers/auth0'
import { getServerSession } from 'next-auth/next'
import type { ExtendedSession } from '@/types'
export const authConfig: NextAuthOptions = {
providers: [
// CredentialsProvider({
// name: 'Login to your account',
// credentials: {
// email: {
// label: 'Email address',
// type: 'text',
// placeholder: 'your@email.com"'
// },
// password: {
// label: 'Password',
// type: 'password',
// placeholder: 'Your password'
// },
// },
// async authorize(credentials) {
// if (!credentials || !credentials.email || !credentials.password) {
// return null;
// }
// const user = await prisma.user.findUnique({
// where: { email: credentials.email }
// });
// if (!user) {
// return null;
// }
// const isPasswordValid = await compare(
// credentials.password,
// user.password
// );
// if (!isPasswordValid) {
// return null;
// }
// const { password, ...userWithoutPassword } = user;
// return userWithoutPassword as User;
// }
// }),
GitHubProvider({
clientId: process.env.GITHUB_ID as string,
clientSecret: process.env.GITHUB_SECRET as string,
}),
GoogleProvider({
clientId: process.env.GOOGLE_ID as string,
clientSecret: process.env.GOOGLE_SECRET as string,
}),
Auth0Provider({
clientId: process.env.AUTH0_CLIENT_ID as string,
clientSecret: process.env.AUTH0_CLIENT_SECRET as string,
issuer: process.env.AUTH0_ISSUER as string
}),
],
pages: {
signIn: '/signin'
},
adapter: PrismaAdapter(prisma),
secret: process.env.NEXTAUTH_SECRET,
session: {
strategy: 'jwt',
},
callbacks: {
// Add user ID to session from token
session: async ({ session, token }) => {
return {
...session,
user: {
...session.user,
id: token.sub,
},
}
}
}
// callbacks: {
// session: ({ session, token }) => {
// return {
// ...session,
// user: {
// ...session.user,
// id: token.id,
// },
// };
// },
// jwt: ({ token, user }) => {
// if (user) {
// const u = user as unknown as any;
// return {
// ...token,
// id: u.id,
// };
// }
// return token;
// },
// },
};
export function getSession(): Promise<ExtendedSession> {
return getServerSession(authConfig) as Promise<ExtendedSession>
}