22 lines
432 B
TypeScript
22 lines
432 B
TypeScript
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;
|
|
}
|
|
}
|