fix fayda

This commit is contained in:
natib21
2026-07-03 09:32:41 +00:00
parent b218179d72
commit 48db0b240b
3 changed files with 35 additions and 2 deletions

View File

@@ -38,7 +38,8 @@ async function bootstrap() {
maxAge: 86400, // cache preflight for 24h to cut chatter in dev
});
app.setGlobalPrefix("api");
// /callback stays un-prefixed: it's the Fayda OAuth redirect_uri ack endpoint.
app.setGlobalPrefix("api", { exclude: ["callback"] });
// enableImplicitConversion is OFF: class-transformer's implicit boolean
// coercion turns any non-empty multipart/form-data string (including the
// literal "false") into `true`, silently corrupting flags like isHazardous

View File

@@ -0,0 +1,31 @@
import { Controller, Get, Query } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { IsPublic } from '@tria-plc/api-common/modules/auth/decorators/public.decorator';
import { VerifaydaCallbackDto } from './verifayda.dto';
/**
* Plain acknowledgement endpoint for the Fayda redirect_uri when it points at
* the API instead of the web app (e.g. MOBILE clients or connectivity checks).
* Registered at /callback (excluded from the global /api prefix in main.ts).
* It does NOT consume the verification session — the client must still call
* GET /api/fayda/verification/complete with the echoed code+state.
*/
@ApiTags('Fayda Verification')
@Controller('callback')
export class FaydaCallbackController {
@Get()
@IsPublic()
@ApiOperation({ summary: 'Acknowledge a Fayda redirect (returns OK, echoes code/state)' })
@ApiOkResponse({
schema: { example: { status: 'ok', code: '...', state: '...' } },
})
ok(@Query() query: VerifaydaCallbackDto) {
return {
status: 'ok',
...(query.code ? { code: query.code } : {}),
...(query.state ? { state: query.state } : {}),
...(query.error ? { error: query.error } : {}),
...(query.error_description ? { error_description: query.error_description } : {}),
};
}
}

View File

@@ -1,12 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { VerifaydaController } from './verifayda.controller';
import { FaydaCallbackController } from './fayda-callback.controller';
import { VerifaydaService } from './verifayda.service';
import { FaydaVerificationSession } from './entities/fayda-verification-session.entity';
@Module({
imports: [TypeOrmModule.forFeature([FaydaVerificationSession])],
controllers: [VerifaydaController],
controllers: [VerifaydaController, FaydaCallbackController],
providers: [VerifaydaService],
exports: [VerifaydaService],
})