deckhearth/pages/api/auth/verify.js
Randall Stillwell 1cc2e28423 Migrate Deck Hearth off Vercel/Neon to homelab Dokploy stack.
Replace @vercel/postgres, Blob, and Upstash with lib/sql.js, MinIO object
storage, and CT 102 Redis rate limits. Add Dockerfile for Dokploy deploy,
homelab runbooks, Neon data-copy helper, and point CI smoke/visual at the
homelab URL instead of Vercel previews.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-15 09:32:13 -05:00

45 lines
No EOL
1.2 KiB
JavaScript

import { sql } from '../../../lib/sql.js';
import jwt from 'jsonwebtoken';
import { JWT_SECRET } from '../../../lib/auth-secret.js';
export default async function handler(req, res) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}
try {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Authentication required' });
}
const token = authHeader.substring(7);
try {
const decoded = jwt.verify(token, JWT_SECRET);
// Get user data from database
const result = await sql`
SELECT id, email, role, created_at
FROM users
WHERE id = ${decoded.userId}
`;
if (result.rows.length === 0) {
return res.status(401).json({ error: 'User not found' });
}
const user = result.rows[0];
res.status(200).json(user);
} catch (jwtError) {
console.error('JWT verification error:', jwtError);
return res.status(401).json({ error: 'Invalid token' });
}
} catch (error) {
console.error('Auth verification error:', error);
res.status(500).json({ error: 'Internal server error' });
}
}