add: wip
This commit is contained in:
64
lib/nextauth.ts
Normal file
64
lib/nextauth.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { PrismaAdapter } from "@auth/prisma-adapter"
|
||||
import NextAuth, { NextAuthOptions, User } from "next-auth"
|
||||
import Github from "next-auth/providers/github"
|
||||
import prisma from "./prisma"
|
||||
import { Adapter } from "next-auth/adapters"
|
||||
|
||||
export const authOptions: NextAuthOptions = {
|
||||
providers: [
|
||||
Github({
|
||||
clientId: process.env.GITHUB_ID as string,
|
||||
clientSecret: process.env.GITHUB_SECRET as string,
|
||||
profile(profile, tokens) {
|
||||
return {
|
||||
id: profile.id,
|
||||
name: profile.name,
|
||||
email: profile.email,
|
||||
image: profile.avatar_url,
|
||||
username: profile.login,
|
||||
} as User;
|
||||
},
|
||||
}),
|
||||
],
|
||||
adapter: PrismaAdapter(prisma) as Adapter,
|
||||
pages: {
|
||||
signIn: "/sign-in",
|
||||
},
|
||||
session: {
|
||||
strategy: "jwt",
|
||||
},
|
||||
callbacks: {
|
||||
session: ({ session, token }) => {
|
||||
return {
|
||||
...session,
|
||||
user: {
|
||||
...session.user,
|
||||
id: token.id,
|
||||
username: token.username,
|
||||
},
|
||||
};
|
||||
},
|
||||
jwt: ({ token, user }) => {
|
||||
if (user) {
|
||||
const u = user as unknown as any;
|
||||
return {
|
||||
...token,
|
||||
id: u.id,
|
||||
username: u.username,
|
||||
};
|
||||
}
|
||||
return token;
|
||||
},
|
||||
},
|
||||
events: {
|
||||
createUser: async ({ user }) => {
|
||||
await prisma.workspace.create({
|
||||
data: {
|
||||
name: user.username + "'s Personal",
|
||||
ownerId: user.id,
|
||||
slug: user.username.toLowerCase(),
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
15
lib/prisma.ts
Normal file
15
lib/prisma.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prismaClientSingleton = () => {
|
||||
return new PrismaClient()
|
||||
}
|
||||
|
||||
declare global {
|
||||
var prismaGlobal: undefined | ReturnType<typeof prismaClientSingleton>
|
||||
}
|
||||
|
||||
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton()
|
||||
|
||||
export default prisma
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalThis.prismaGlobal = prisma
|
||||
6
lib/utils.ts
Normal file
6
lib/utils.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type ClassValue, clsx } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
Reference in New Issue
Block a user