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
181 changes: 181 additions & 0 deletions harvest-finance/backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion harvest-finance/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@
"exceljs": "^4.4.0",
"fast-csv": "^5.0.5",
"graphql": "^16.14.0",
"joi": "^18.2.3",
"passport": "^0.7.0",
"passport-github2": "^0.1.12",
"passport-google-oauth20": "^2.0.0",
"passport-jwt": "^4.0.1",
"pdfkit": "^0.18.0",
"pg": "^8.18.0",
Expand Down Expand Up @@ -100,6 +103,8 @@
"@types/express": "^5.0.0",
"@types/jest": "^30.0.0",
"@types/node": "^22.10.7",
"@types/passport-github2": "^1.2.9",
"@types/passport-google-oauth20": "^2.0.17",
"@types/passport-jwt": "^4.0.1",
"@types/pino": "^7.0.4",
"@types/pino-http": "^5.8.4",
Expand Down Expand Up @@ -137,4 +142,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}
2 changes: 2 additions & 0 deletions harvest-finance/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
SorobanEvent,
Transaction,
User,
UserOAuthLink,
Vault,
VaultDeposit,
Verification,
Expand Down Expand Up @@ -109,6 +110,7 @@ import { WebhooksModule } from './webhooks/webhooks.module';
database: configService.get<string>('DB_NAME'),
entities: [
User,
UserOAuthLink,
Order,
Transaction,
Verification,
Expand Down
56 changes: 55 additions & 1 deletion harvest-finance/backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
Req,
HttpCode,
HttpStatus,
Get,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import type { Request } from 'express';
import {
ApiTags,
Expand Down Expand Up @@ -173,7 +175,7 @@ export class AuthController {
@UseGuards(JwtAuthGuard)
@HttpCode(HttpStatus.OK)
@ApiBearerAuth()
@ApiOperation({ summary: 'Logout user', description: 'Invalidates the user's refresh token, effectively logging them out. Requires a valid JWT access token in the Authorization header.' })
@ApiOperation({ summary: 'Logout user', description: 'Invalidates the user\'s refresh token, effectively logging them out. Requires a valid JWT access token in the Authorization header.' })
@ApiResponse({
status: 200,
description: 'Logged out successfully',
Expand Down Expand Up @@ -349,4 +351,56 @@ export class AuthController {
},
};
}

/**
* Redirect to Google OAuth provider
*/
@Get('google')
@UseGuards(AuthGuard('google'))
@ApiOperation({ summary: 'Login via Google', description: 'Redirects to Google login consent screen.' })
async googleAuth(@Req() req) {
// Handled by passport guard
}

/**
* Google OAuth callback handler
*/
@Get('google/callback')
@UseGuards(AuthGuard('google'))
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Google Auth callback', description: 'Handles redirect callback from Google, registers/links account, and issues JWT tokens.' })
@ApiResponse({
status: 200,
description: 'Successfully authenticated',
type: AuthResponseDto,
})
async googleAuthRedirect(@Req() req): Promise<AuthResponseDto> {
return this.authService.loginWithOAuth(req.user);
}

/**
* Redirect to GitHub OAuth provider
*/
@Get('github')
@UseGuards(AuthGuard('github'))
@ApiOperation({ summary: 'Login via GitHub', description: 'Redirects to GitHub login screen.' })
async githubAuth(@Req() req) {
// Handled by passport guard
}

/**
* GitHub OAuth callback handler
*/
@Get('github/callback')
@UseGuards(AuthGuard('github'))
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'GitHub Auth callback', description: 'Handles redirect callback from GitHub, registers/links account, and issues JWT tokens.' })
@ApiResponse({
status: 200,
description: 'Successfully authenticated',
type: AuthResponseDto,
})
async githubAuthRedirect(@Req() req): Promise<AuthResponseDto> {
return this.authService.loginWithOAuth(req.user);
}
}
Loading
Loading