Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions harvest-finance/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
Notification,
Order,
Reward,
Session,
SorobanEvent,
Transaction,
User,
Expand Down Expand Up @@ -93,6 +94,7 @@ import { VaultReservation } from './vaults/entities/vault-reservation.entity';
import { Session } from './database/entities/session.entity';
import { SecurityEvent } from './database/entities/security-event.entity';
import { CreateVaultApyHistory1700000000017 } from './database/migrations/1700000000017-CreateVaultApyHistory';
import { CreateSessionsAndOAuthLinks1700000000022 } from './database/migrations/1700000000022-CreateSessionsAndOAuthLinks';
import { AddRefreshTokenRotation1700000000022 } from './database/migrations/1700000000022-AddRefreshTokenRotation';
import { DomainEventsModule } from './domain-events';
import { DomainEventHandlersModule } from './common/events';
Expand Down Expand Up @@ -124,6 +126,7 @@ import { CreateCustodialWallets1700000000021 } from './database/migrations/17000
entities: [
User,
UserOAuthLink,
Session,
Order,
Transaction,
Verification,
Expand Down Expand Up @@ -163,6 +166,7 @@ import { CreateCustodialWallets1700000000021 } from './database/migrations/17000
CreateVaultReservations1700000000018,
AddDepositorConcentrationThreshold1700000000022,
CreateVaultApyHistory1700000000017,
CreateSessionsAndOAuthLinks1700000000022,
CreateCustodialWallets1700000000021,
],
synchronize: false,
Expand Down
24 changes: 20 additions & 4 deletions harvest-finance/backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
HttpCode,
HttpStatus,
Get,
Query,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import type { Request } from 'express';
Expand Down Expand Up @@ -127,8 +128,13 @@ export class AuthController {
status: 500,
description: 'Internal server error',
})
async login(@Body() loginDto: LoginDto): Promise<AuthResponseDto> {
return this.authService.login(loginDto);
async login(@Body() loginDto: LoginDto, @Req() req: Request): Promise<AuthResponseDto> {
const userAgent = req.headers['user-agent'];
const ipAddress =
(req.headers['x-forwarded-for'] as string)?.split(',')[0]?.trim() ??
req.socket?.remoteAddress ??
undefined;
return this.authService.login(loginDto, userAgent, ipAddress);
}

/**
Expand Down Expand Up @@ -375,7 +381,12 @@ export class AuthController {
type: AuthResponseDto,
})
async googleAuthRedirect(@Req() req): Promise<AuthResponseDto> {
return this.authService.loginWithOAuth(req.user);
const userAgent = req.headers['user-agent'];
const ipAddress =
(req.headers['x-forwarded-for'] as string)?.split(',')[0]?.trim() ??
req.socket?.remoteAddress ??
undefined;
return this.authService.loginWithOAuth(req.user, userAgent, ipAddress);
}

/**
Expand All @@ -401,7 +412,12 @@ export class AuthController {
type: AuthResponseDto,
})
async githubAuthRedirect(@Req() req): Promise<AuthResponseDto> {
return this.authService.loginWithOAuth(req.user);
const userAgent = req.headers['user-agent'];
const ipAddress =
(req.headers['x-forwarded-for'] as string)?.split(',')[0]?.trim() ??
req.socket?.remoteAddress ??
undefined;
return this.authService.loginWithOAuth(req.user, userAgent, ipAddress);
}

@Get('verify-email')
Expand Down
35 changes: 30 additions & 5 deletions harvest-finance/backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthController } from './auth.controller';
import { SessionsController } from './sessions.controller';
import { AuthService } from './auth.service';
import { JwtStrategy } from './strategies/jwt.strategy';
import { StellarStrategy } from './strategies/stellar.strategy';
Expand All @@ -19,16 +21,39 @@ import { CustodialWalletService } from '../wallets/custodial-wallet.service';

@Module({
imports: [
TypeOrmModule.forFeature([User, UserOAuthLink, Session]),
TypeOrmModule.forFeature([User, UserOAuthLink, CustodialWallet]),
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.register({
secret: 'super_secret_jwt_key',
signOptions: {
expiresIn: '1h',
},
JwtModule.registerAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
secret:
configService.get<string>('JWT_SECRET') || 'super_secret_jwt_key',
signOptions: {
expiresIn:
configService.get<string>('JWT_EXPIRES_IN') || '1h',
},
}),
}),
CommonModule,
],
controllers: [AuthController, SessionsController],
providers: [
AuthService,
JwtStrategy,
StellarStrategy,
GoogleStrategy,
GithubStrategy,
],
exports: [
AuthService,
JwtStrategy,
StellarStrategy,
GoogleStrategy,
GithubStrategy,
PassportModule,
],
controllers: [AuthController],
providers: [AuthService, JwtStrategy, StellarStrategy, GoogleStrategy, GithubStrategy, CustodialWalletService],
exports: [AuthService, JwtStrategy, StellarStrategy, GoogleStrategy, GithubStrategy, PassportModule, CustodialWalletService],
Expand Down
Loading
Loading