first commit
This commit is contained in:
22
src/auth/auth.service.ts
Normal file
22
src/auth/auth.service.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
constructor(
|
||||
private jwtService: JwtService,
|
||||
private configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async login(password: string) {
|
||||
const envPassword = this.configService.get<string>('PASSWORD');
|
||||
if (password !== envPassword) {
|
||||
throw new UnauthorizedException('Incorrect password');
|
||||
}
|
||||
const payload = { username: 'admin', sub: 'admin' };
|
||||
return {
|
||||
accessToken: this.jwtService.sign(payload),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user