2024-02-24 11:18:58 +02:00
|
|
|
import { validateApiToken } from '@documenso/lib/server-only/webhooks/zapier/validateApiToken';
|
|
|
|
|
|
2025-01-02 15:33:37 +11:00
|
|
|
export const testCredentialsHandler = async (req: Request) => {
|
2024-02-24 11:18:58 +02:00
|
|
|
try {
|
2025-01-02 15:33:37 +11:00
|
|
|
const authorization = req.headers.get('authorization');
|
|
|
|
|
|
|
|
|
|
if (!authorization) {
|
|
|
|
|
throw new Error('Missing authorization header');
|
|
|
|
|
}
|
2024-02-26 22:24:23 +11:00
|
|
|
|
2024-02-27 15:22:02 +02:00
|
|
|
const result = await validateApiToken({ authorization });
|
2024-02-24 11:18:58 +02:00
|
|
|
|
2025-01-02 15:33:37 +11:00
|
|
|
return Response.json({
|
2024-02-28 08:10:38 +02:00
|
|
|
name: result.team?.name ?? result.user.name,
|
2024-02-24 11:18:58 +02:00
|
|
|
});
|
|
|
|
|
} catch (err) {
|
2025-01-02 15:33:37 +11:00
|
|
|
return Response.json(
|
|
|
|
|
{
|
|
|
|
|
message: 'Internal Server Error',
|
|
|
|
|
},
|
|
|
|
|
{ status: 500 },
|
|
|
|
|
);
|
2024-02-24 11:18:58 +02:00
|
|
|
}
|
|
|
|
|
};
|