fix: Skip JWT auth for edge device endpoints
This commit is contained in:
parent
14e76f2cdf
commit
55bdef78e4
1 changed files with 11 additions and 2 deletions
|
|
@ -40,8 +40,15 @@ const profileSchema = z.object({
|
|||
});
|
||||
|
||||
export async function environmentRoutes(fastify: FastifyInstance) {
|
||||
// Auth middleware
|
||||
fastify.addHook('onRequest', async (request) => {
|
||||
// Auth middleware - skip for edge device endpoints (they use API key auth)
|
||||
const edgeEndpoints = ['/heartbeat', '/ingest'];
|
||||
fastify.addHook('onRequest', async (request, reply) => {
|
||||
// Skip JWT for edge device endpoints
|
||||
const path = request.url.split('?')[0];
|
||||
if (edgeEndpoints.some(ep => path.endsWith(ep))) {
|
||||
return; // Edge endpoints handle their own auth
|
||||
}
|
||||
|
||||
try {
|
||||
await request.jwtVerify();
|
||||
} catch (err) {
|
||||
|
|
@ -491,10 +498,12 @@ export async function environmentRoutes(fastify: FastifyInstance) {
|
|||
*/
|
||||
fastify.post('/heartbeat', {
|
||||
preHandler: async (request, reply) => {
|
||||
// For demo: Accept any Bearer token (no validation)
|
||||
const authHeader = request.headers.authorization;
|
||||
if (!authHeader?.startsWith('Bearer ')) {
|
||||
return reply.status(401).send({ error: 'API key required' });
|
||||
}
|
||||
// TODO: In production, validate API key against registered edge devices
|
||||
},
|
||||
handler: async (request, reply) => {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue