Merge branch 'main' of https://gittea.biveki.ru/BivekiGroup/prism
This commit is contained in:
@ -3,6 +3,16 @@ import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
// Настройка CORS для работы с фронтендом
|
||||
app.enableCors({
|
||||
origin: true, // В разработке разрешаем все источники
|
||||
credentials: true,
|
||||
allowedHeaders: ['Content-Type', 'Authorization'],
|
||||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||
});
|
||||
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
console.log(`Application is running on: http://localhost:${process.env.PORT ?? 3000}/graphql`);
|
||||
}
|
||||
bootstrap();
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { AuthService } from './auth.service';
|
||||
import { AuthResolver } from './auth.resolver';
|
||||
import { JwtStrategy } from './strategies/jwt.strategy';
|
||||
@ -10,9 +11,15 @@ import { UsersModule } from '../users/users.module';
|
||||
imports: [
|
||||
UsersModule,
|
||||
PassportModule,
|
||||
JwtModule.register({
|
||||
secret: process.env.JWT_SECRET || 'secret',
|
||||
signOptions: { expiresIn: process.env.JWT_EXPIRATION || '7d' },
|
||||
JwtModule.registerAsync({
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => ({
|
||||
secret: configService.get<string>('JWT_SECRET') || 'secret',
|
||||
signOptions: {
|
||||
expiresIn: configService.get<string>('JWT_EXPIRATION') || '7d'
|
||||
},
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
],
|
||||
providers: [AuthService, AuthResolver, JwtStrategy],
|
||||
|
@ -1,15 +1,19 @@
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { UsersService } from '../../users/users.service';
|
||||
|
||||
@Injectable()
|
||||
export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
constructor(private usersService: UsersService) {
|
||||
constructor(
|
||||
private usersService: UsersService,
|
||||
private configService: ConfigService,
|
||||
) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: process.env.JWT_SECRET || 'secret',
|
||||
secretOrKey: configService.get<string>('JWT_SECRET') || 'secret',
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user