-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
128 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
|
||
// eslint-disable-next-line import/no-mutable-exports | ||
// biome-ignore lint/style/useConst: <explanation> | ||
let prisma: PrismaClient | ||
|
||
if (process.env.NODE_ENV === 'production') { | ||
prisma = new PrismaClient() | ||
} else { | ||
const globalWithPrisma = global as typeof globalThis & { | ||
prisma: PrismaClient | ||
} | ||
if (!globalWithPrisma.prisma) { | ||
globalWithPrisma.prisma = new PrismaClient() | ||
} | ||
prisma = globalWithPrisma.prisma | ||
} | ||
prisma = new PrismaClient() | ||
|
||
// if (process.env.NODE_ENV === 'production') { | ||
// prisma = new PrismaClient() | ||
// } else { | ||
// const globalWithPrisma = global as typeof globalThis & { | ||
// prisma: PrismaClient | ||
// } | ||
// if (!globalWithPrisma.prisma) { | ||
// globalWithPrisma.prisma = new PrismaClient() | ||
// } | ||
// prisma = globalWithPrisma.prisma | ||
// } | ||
|
||
export default prisma |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import { clerkMiddleware, getAuth } from '@hono/clerk-auth' | ||
import { clerkMiddleware } from '@hono/clerk-auth' | ||
|
||
export const authMiddleware = clerkMiddleware | ||
export { getAuth } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { zValidator } from '@hono/zod-validator' | ||
import { getAuth } from '@hono/clerk-auth' | ||
import { Hono } from 'hono' | ||
import { zLogin } from '../validation' | ||
import { HTTPException } from 'hono/http-exception' | ||
import { findUserById } from '../services/user.service' | ||
|
||
const authApp = new Hono() | ||
const router = new Hono() | ||
|
||
authApp.get('/login', zValidator('query', zLogin), (c) => { | ||
const { email, password } = c.req.valid('query') | ||
return c.json({ | ||
message: 'Login', | ||
email, | ||
password, | ||
env: process.env.NODE_ENV, | ||
}) | ||
router.get('/me', async (c) => { | ||
const auth = getAuth(c) | ||
|
||
if (!auth?.userId) { | ||
throw new HTTPException(401, { message: 'unauthorized' }) | ||
} | ||
|
||
const user = await findUserById(auth.userId) | ||
|
||
if (!user) { | ||
throw new HTTPException(401, { message: 'unauthorized' }) | ||
} | ||
|
||
return c.json(user) | ||
}) | ||
|
||
export default authApp | ||
export default router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import prisma from '@/lib/prisma' | ||
|
||
export async function findUserById(id: string) { | ||
return await prisma.user.findUnique({ | ||
where: { | ||
id, | ||
}, | ||
}) | ||
} |