fix: use APP_GUARD provider for global authentication guard
- Replace manual guard instantiation with DI-managed APP_GUARD provider - Fixes request timeout issue caused by improper Passport JWT strategy initialization - Add @Public() decorator to remaining sync endpoints for public access - Remove unused Reflector import from main.ts
This commit is contained in:
parent
8fbde18d02
commit
b39972102a
@ -1,6 +1,7 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { APP_GUARD } from '@nestjs/core';
|
||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import { ArticlesModule } from './modules/articles.module';
|
import { ArticlesModule } from './modules/articles.module';
|
||||||
@ -23,6 +24,7 @@ import {
|
|||||||
} from './modules/entities';
|
} from './modules/entities';
|
||||||
import { ShareEvent } from './modules/analytics/analytics.entity';
|
import { ShareEvent } from './modules/analytics/analytics.entity';
|
||||||
import { PushSubscriptionEntity } from './modules/push/push-subscription.entity';
|
import { PushSubscriptionEntity } from './modules/push/push-subscription.entity';
|
||||||
|
import { JwtAuthPublicGuard } from './modules/auth/jwt-auth-public.guard';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@ -61,6 +63,12 @@ import { PushSubscriptionEntity } from './modules/push/push-subscription.entity'
|
|||||||
PushModule,
|
PushModule,
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [
|
||||||
|
AppService,
|
||||||
|
{
|
||||||
|
provide: APP_GUARD,
|
||||||
|
useClass: JwtAuthPublicGuard,
|
||||||
|
},
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { NestFactory, Reflector } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { ValidationPipe } from '@nestjs/common';
|
import { ValidationPipe } from '@nestjs/common';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import { JwtAuthPublicGuard } from './modules/auth/jwt-auth-public.guard';
|
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
@ -36,10 +35,6 @@ async function bootstrap() {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Apply global authentication guard
|
|
||||||
const reflector = app.get(Reflector);
|
|
||||||
app.useGlobalGuards(new JwtAuthPublicGuard(reflector));
|
|
||||||
|
|
||||||
const port = process.env.PORT ?? 3000;
|
const port = process.env.PORT ?? 3000;
|
||||||
const host = '0.0.0.0'; // Bind to all interfaces for Docker
|
const host = '0.0.0.0'; // Bind to all interfaces for Docker
|
||||||
await app.listen(port, host);
|
await app.listen(port, host);
|
||||||
|
|||||||
@ -134,12 +134,14 @@ export class StrapiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post('sync/live-blogs')
|
@Post('sync/live-blogs')
|
||||||
|
@Public()
|
||||||
async syncAllLiveBlogs() {
|
async syncAllLiveBlogs() {
|
||||||
await this.strapiService.syncLiveBlogs();
|
await this.strapiService.syncLiveBlogs();
|
||||||
return { message: 'Live blogs sync completed' };
|
return { message: 'Live blogs sync completed' };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('sync/everything')
|
@Post('sync/everything')
|
||||||
|
@Public()
|
||||||
async syncEverything() {
|
async syncEverything() {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this.strapiService.syncArticles(),
|
this.strapiService.syncArticles(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user