Refactor: Fully migrated to direct PostgreSQL, implemented Public API v1, fixed Vercel deployment conflicts, and updated documentation
This commit is contained in:
21
lib/api-auth.ts
Normal file
21
lib/api-auth.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { db } from './db';
|
||||
|
||||
export async function validateApiKey(apiKey: string | null) {
|
||||
if (!apiKey) return null;
|
||||
|
||||
try {
|
||||
const result = await db.query(
|
||||
'SELECT * FROM merchants WHERE api_key = $1 LIMIT 1',
|
||||
[apiKey]
|
||||
);
|
||||
|
||||
if (result.rows.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return result.rows[0];
|
||||
} catch (error) {
|
||||
console.error('API Key Validation Error:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user