UNPKG

@next-nest-auth/nestauth

Version:

NestAuth is an authentication solution for NestJS applications, designed to handle user login, session management, and token-based authentication (JWT). It integrates seamlessly with Next.js and other frontends to provide a unified authentication system,

27 lines (24 loc) 806 B
import { PassportStrategy } from "@nestjs/passport"; import { Strategy } from "passport-custom"; import { Inject, Injectable, UnauthorizedException } from "@nestjs/common"; import { NestAuthInterface } from "./nestauth.interface"; import * as macaddress from "macaddress"; @Injectable() export class NestAuthLocalStrategy extends PassportStrategy( Strategy, "nestauth-local" ) { constructor( @Inject("UserService") private readonly userService: NestAuthInterface ) { super(); } async validate(req: Request): Promise<any> { const user = await this.userService.validateUser(req.body); if (!user) { throw new UnauthorizedException("Invalid credentials"); } user.macId = await macaddress.one(); return user; } }