import { Hono } from 'hono';
import type { MeResponse } from '@solelog/shared';
import { auth } from '../auth';

export const me = new Hono();

me.get('/api/me', async (c) => {
  const session = await auth.api.getSession({ headers: c.req.raw.headers });
  if (!session) {
    return c.json({ error: 'Unauthorized' }, 401);
  }
  const body: MeResponse = {
    user: {
      id: session.user.id,
      email: session.user.email,
      name: session.user.name,
    },
  };
  return c.json(body);
});
