import { SUser } from '@app/playground/test-model'
import { env as clientEnv } from '@client'
import { zValidator } from '@hono/zod-validator'
import { clerkMiddleware, getAuth } from '@lib/hono-client/clerk-middleware'
import { env as serverEnv } from '@server'
import { Hono } from 'hono'
import { handle } from 'hono/vercel'
export const runtime = 'edge'
const app = new Hono().basePath('/api')
app.use(
'*',
clerkMiddleware({
secretKey: serverEnv.CLERK_SECRET_KEY,
publishableKey: clientEnv.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
}),
)
const route = app
.get('/user', zValidator('query', SUser), (c) => {
const { name, email } = c.req.valid('query')
const auth = getAuth(c)
if (!auth?.userId) {
return c.json({
message: 'You are not logged in.',
})
}
return c.json({
message: 'You are logged in!',
userId: auth.userId,
name,
email,
})
})
export const GET = handle(app)
export const POST = handle(app)
export type AppType = typeof route
import { SUser } from '@app/playground/test-model'
import { env as clientEnv } from '@client'
import { zValidator } from '@hono/zod-validator'
import { clerkMiddleware, getAuth } from '@lib/hono-client/clerk-middleware'
import { env as serverEnv } from '@server'
import { Hono } from 'hono'
import { handle } from 'hono/vercel'
export const runtime = 'edge'
const app = new Hono().basePath('/api')
app.use(
'*',
clerkMiddleware({
secretKey: serverEnv.CLERK_SECRET_KEY,
publishableKey: clientEnv.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
}),
)
const route = app
.get('/user', zValidator('query', SUser), (c) => {
const { name, email } = c.req.valid('query')
const auth = getAuth(c)
if (!auth?.userId) {
return c.json({
message: 'You are not logged in.',
})
}
return c.json({
message: 'You are logged in!',
userId: auth.userId,
name,
email,
})
})
export const GET = handle(app)
export const POST = handle(app)
export type AppType = typeof route