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) {
|
export async function environmentRoutes(fastify: FastifyInstance) {
|
||||||
// Auth middleware
|
// Auth middleware - skip for edge device endpoints (they use API key auth)
|
||||||
fastify.addHook('onRequest', async (request) => {
|
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 {
|
try {
|
||||||
await request.jwtVerify();
|
await request.jwtVerify();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -491,10 +498,12 @@ export async function environmentRoutes(fastify: FastifyInstance) {
|
||||||
*/
|
*/
|
||||||
fastify.post('/heartbeat', {
|
fastify.post('/heartbeat', {
|
||||||
preHandler: async (request, reply) => {
|
preHandler: async (request, reply) => {
|
||||||
|
// For demo: Accept any Bearer token (no validation)
|
||||||
const authHeader = request.headers.authorization;
|
const authHeader = request.headers.authorization;
|
||||||
if (!authHeader?.startsWith('Bearer ')) {
|
if (!authHeader?.startsWith('Bearer ')) {
|
||||||
return reply.status(401).send({ error: 'API key required' });
|
return reply.status(401).send({ error: 'API key required' });
|
||||||
}
|
}
|
||||||
|
// TODO: In production, validate API key against registered edge devices
|
||||||
},
|
},
|
||||||
handler: async (request, reply) => {
|
handler: async (request, reply) => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue