22 lines
638 B
TypeScript
22 lines
638 B
TypeScript
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),
|
|
};
|
|
}
|
|
} |