nestjs-auth-kit
Version:
A modular and flexible authentication kit for NestJS with JWT, social login, OTP, and password reset.
64 lines (53 loc) • 1.78 kB
text/typescript
import { Controller, Get, Post, Body, Req, UseGuards } from '@nestjs/common';
import { AuthService } from './auth.service';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { RolesGuard } from './guards/roles.guard';
import { Roles } from './decorators/roles.decorator';
import { RegisterDto } from './dto/register.dto';
('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
('register')
async register(() registerDto: RegisterDto) {
return this.authService.register(registerDto);
}
('login')
async login(() loginDto: any) {
return this.authService.login(loginDto);
}
('google')
async googleLogin(() req: any) {
return this.authService.validateGoogleUser(req.user);
}
('facebook')
async facebookLogin(() req: any) {
return this.authService.validateFacebookUser(req.user);
}
('otp')
async sendOtp(('email') email: string) {
return this.authService.sendOtp(email);
}
('otp/verify')
async verifyOtp(('email') email: string, ('otp') otp: string) {
return this.authService.verifyOtp(email, otp);
}
('password-reset')
async resetPassword(
('email') email: string,
('otp') otp: string,
('newPassword') newPassword: string,
) {
return this.authService.resetPassword(email, otp, newPassword);
}
('me')
(JwtAuthGuard)
async getProfile(() req: any) {
return req.user;
}
('admin')
(JwtAuthGuard, RolesGuard)
('admin')
getAdminData() {
return { message: 'Admin data' };
}
}