Files
scheduler-back/src/middleware/auth/auth.service.ts
geonhee-min 17335a26e7
All checks were successful
Test CI / build (push) Successful in 1m22s
issue #63
- 일정 상세 조회 기능 구현 중
2025-12-15 17:35:35 +09:00

26 lines
696 B
TypeScript

import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
@Injectable()
export class AuthService {
constructor(private readonly jwtService: JwtService) {}
generateTokens(id: string) {
const accessToken = this.jwtService.sign({id: id}, { expiresIn: '5m' });
const refreshToken = this.jwtService.sign({id: id}, { expiresIn: '7d' });
return { accessToken, refreshToken };
}
refreshTokens(id: string) {
try {
return this.generateTokens(id);
} catch (e) {
throw new UnauthorizedException('Invalid Refresh Token');
}
}
validateToken(token: string) {
return this.jwtService.verify(token);
}
}