Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:socialauth #187

Merged
merged 3 commits into from
Feb 27, 2025
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
2 changes: 2 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ JWT_ADMIN_SECRET=super-secret-admin-jwt-key
JWT_ADMIN_EXPIRATION=15m
JWT_ADMIN_REFRESH_SECRET=super-secret-admin-refresh-key
JWT_ADMIN_REFRESH_EXPIRATION=7d
GOOGLE_OAUTH_CLIENT_ID=your-google-client-id,
GOOGLE_OAUTH_CLEINT_SECRET=your-google-client-secrete

# Application
PORT=3000
Expand Down
2 changes: 2 additions & 0 deletions backend/config/jwt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export default registerAs('jwt', () => ({
process.env.JWT_REFRESH_TOKEN_TTL ?? '7776000',
10,
),
googleClient_id: process.env.GOOGLE_OAUTH_CLIENT_ID,
googleClient_secret: process.env.GOOGLE_OAUTH_CLEINT_SECRET,
}));
172 changes: 171 additions & 1 deletion backend/package-lock.json

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

5 changes: 3 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"migration:run": "npm run typeorm -- migration:run -d ./src/data-source.ts"
},
"dependencies": {
"@nestjs/cache-manager": "^3.0.0",
"@nestjs-modules/mailer": "^2.0.2",
"@nestjs/cache-manager": "^3.0.0",
"@nestjs/common": "^11.0.10",
"@nestjs/config": "^4.0.0",
"@nestjs/core": "^11.0.10",
Expand All @@ -43,9 +43,10 @@
"class-validator": "^0.14.1",
"dep": "^0.18.3",
"dotenv": "^16.4.7",
"ioredis": "^5.5.0",
"ejs": "^3.1.10",
"google-auth-library": "^9.15.1",
"handlebars": "^4.7.8",
"ioredis": "^5.5.0",
"jsonwebtoken": "^9.0.2",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
Expand Down
5 changes: 4 additions & 1 deletion backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { RefreshTokenProvider } from './providers/refresh-token.provider';
import { PassportModule } from '@nestjs/passport';
import { JwtStrategy } from '../../security/strategies/jwt.strategy';
import { SubAdminModule } from 'src/sub-admin/sub-admin.module';
import { GoogleAuthenticationController } from './social/google-authtication.controller';
import { GoogleAuthenticationService } from './social/providers/google-authtication';

@Module({
imports: [
Expand All @@ -25,7 +27,7 @@ import { SubAdminModule } from 'src/sub-admin/sub-admin.module';
signOptions: { expiresIn: '1h' },
}),
],
controllers: [AuthController],
controllers: [AuthController, GoogleAuthenticationController],
providers: [
AuthService,
JwtStrategy,
Expand All @@ -36,6 +38,7 @@ import { SubAdminModule } from 'src/sub-admin/sub-admin.module';
SignInProvider,
GenerateTokenProvider,
RefreshTokenProvider,
GoogleAuthenticationService
],
exports: [
AuthService,
Expand Down
6 changes: 6 additions & 0 deletions backend/src/auth/social/dtos/google-token-dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {IsNotEmpty} from 'class-validator'

export class GoogleTokenDto {
@IsNotEmpty()
token: string
}
18 changes: 18 additions & 0 deletions backend/src/auth/social/google-authtication.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Body, Controller, Post } from '@nestjs/common';
import { GoogleAuthenticationService } from './providers/google-authtication';
import { GoogleTokenDto } from './dtos/google-token-dto';

@Controller('auth')
export class GoogleAuthenticationController {
constructor(
/*
* inject googleAuthenticationService
*/
private readonly googleAuthenticationService: GoogleAuthenticationService
) {}

@Post('google-authentication')
public authenticate(@Body() googlTokenDto: GoogleTokenDto) {
return this.googleAuthenticationService.authenticate(googlTokenDto)
}
}
10 changes: 10 additions & 0 deletions backend/src/auth/social/google-authtication.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { GoogleAuthenticationController } from './google-authtication.controller';
import { GoogleAuthenticationService } from './providers/google-authtication';

@Module({
controllers: [GoogleAuthenticationController],
providers: [GoogleAuthenticationService]
})

export class GoogleAuthticationModule {}
6 changes: 6 additions & 0 deletions backend/src/auth/social/interfaces/user.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface GoogleInterface {
email: string
firstName: string
lastName: string
googleId: string
}
Loading