Skip to content

Commit

Permalink
feat: remove unsued prisma models, upgraded prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
kcoulsy committed Jan 28, 2024
1 parent e89346c commit cc2a165
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 111 deletions.
137 changes: 98 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@next-auth/prisma-adapter": "1.0.5",
"@next/bundle-analyzer": "12.3.4",
"@playwright/test": "1.41.1",
"@prisma/client": "4.12.0",
"@prisma/client": "5.8.1",
"@radix-ui/react-avatar": "1.0.3",
"@radix-ui/react-dropdown-menu": "2.0.5",
"@radix-ui/react-icons": "1.3.0",
Expand Down Expand Up @@ -146,7 +146,7 @@
"npm-run-all": "4.1.5",
"postcss": "8.4.21",
"prettier": "2.8.1",
"prisma": "4.12.0",
"prisma": "5.8.1",
"sass": "1.57.1",
"sass-loader": "13.0.2",
"storybook": "7.6.10",
Expand Down
47 changes: 6 additions & 41 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ datasource db {
relationMode = "prisma"
}

model CredentialsAuth {
model User {
id String @id @default(cuid())
email String
password String
Expand All @@ -24,45 +24,10 @@ model CredentialsAuth {
stripeCustomerId String?
}

model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
CredentialsAuth CredentialsAuth? @relation(fields: [credentialsAuthId], references: [id])
credentialsAuthId String?
identifier String
token String @unique
expires DateTime
user User? @relation(fields: [userId], references: [id])
userId String?
}
4 changes: 2 additions & 2 deletions src/app/api/e2e/deleteTestUser/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export async function DELETE(request: NextRequest) {
})
.parse(res);

const user = await prisma.credentialsAuth.findFirst({
const user = await prisma.user.findFirst({
where: { email },
});

if (!user) {
return NextResponse.json({ error: 'User is not found' }, { status: 404 });
}

const result = await prisma.credentialsAuth.delete({
const result = await prisma.user.delete({
where: { id: user.id },
});

Expand Down
2 changes: 1 addition & 1 deletion src/app/api/e2e/getTestUserVerificationToken/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function GET(request: NextRequest) {
const { searchParams } = request.nextUrl;
const email = searchParams.get('email');

const user = await prisma.credentialsAuth.findFirst({
const user = await prisma.user.findFirst({
where: { email: email || '' },
include: { verificationToken: true },
});
Expand Down
7 changes: 0 additions & 7 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import NextAuth, { type AuthOptions } from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import { PrismaAdapter } from '@auth/prisma-adapter';
import { prisma } from '@src/server/db/client';
import { loginUser } from '@src/server/services/auth.service';

export const authOptions: AuthOptions = {
// Include user.id on session
session: {
strategy: 'jwt',
maxAge: 60 * 60, // 1h
Expand All @@ -21,10 +18,6 @@ export const authOptions: AuthOptions = {
};
},
},
// Configure one or more authentication providers
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
adapter: PrismaAdapter(prisma),
providers: [
Credentials({
name: 'Credentials',
Expand Down
8 changes: 4 additions & 4 deletions src/server/services/auth.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const loginUser = async ({ email, password }: LoginUser) => {
try {
loginUserSchema.parse({ email, password });

const user = await prisma.credentialsAuth.findFirst({
const user = await prisma.user.findFirst({
where: { email },
});
if (!user) throw new Error('User not found');
Expand Down Expand Up @@ -56,7 +56,7 @@ export const registerUser = async ({ email, password }: RegisterUser) => {
try {
registerUserSchema.parse({ email, password });

const existingEmail = await prisma.credentialsAuth.findFirst({ where: { email } });
const existingEmail = await prisma.user.findFirst({ where: { email } });

if (existingEmail) throw new Error('Email Exists');
// TODO vaidat password with schema
Expand All @@ -69,7 +69,7 @@ export const registerUser = async ({ email, password }: RegisterUser) => {
throw new Error('Password Error');
}

const user = await prisma.credentialsAuth.create({
const user = await prisma.user.create({
data: {
email,
password: hashedPassword,
Expand All @@ -93,7 +93,7 @@ export const registerUser = async ({ email, password }: RegisterUser) => {
*/
export const forgotPassword = async (email: string) => {
try {
const user = await prisma.credentialsAuth.findFirst({ where: { email } });
const user = await prisma.user.findFirst({ where: { email } });

if (!user) throw new Error('Email not found');

Expand Down
4 changes: 2 additions & 2 deletions src/server/services/stripe.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function createCheckoutLink(customerId: string, priceId: string) {
}

export async function findOrCreateStripeCustomer(userId: string) {
const user = await prisma.credentialsAuth.findUnique({
const user = await prisma.user.findUnique({
where: {
id: userId,
},
Expand All @@ -83,7 +83,7 @@ export async function findOrCreateStripeCustomer(userId: string) {

const customer = await createCustomer(user.email);

await prisma.credentialsAuth.update({
await prisma.user.update({
where: {
id: userId,
},
Expand Down
Loading

0 comments on commit cc2a165

Please sign in to comment.