52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import { Controller } from '@nestjs/common';
|
|
import { AuthService } from './services/auth.service';
|
|
import { MessagePattern } from '@nestjs/microservices';
|
|
import { LoginRequest } from './interfaces/auth.interface';
|
|
import { UserInfo } from '@freeblox/shared';
|
|
import { AuthChallenge } from './enums/challenge.enum';
|
|
|
|
@Controller()
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@MessagePattern('auth.login')
|
|
login({ body, ip }: { body: LoginRequest; ip: string }) {
|
|
return this.authService.login(body, ip);
|
|
}
|
|
|
|
@MessagePattern('auth.loginByRefreshToken')
|
|
loginByRefreshToken({ token, ip }: { token: string; ip: string }) {
|
|
return this.authService.loginByRefreshToken(token, ip);
|
|
}
|
|
|
|
@MessagePattern('auth.loginByChallenge')
|
|
loginByChallenge({
|
|
challenge,
|
|
secret,
|
|
body,
|
|
ip,
|
|
}: {
|
|
challenge: AuthChallenge;
|
|
secret: string;
|
|
body: Record<string, string>;
|
|
ip: string;
|
|
}) {
|
|
return this.authService.loginByChallenge(challenge, secret, body, ip);
|
|
}
|
|
|
|
@MessagePattern('auth.verify')
|
|
verify({ token }: { token: string }) {
|
|
return this.authService.verifyAccessToken(token);
|
|
}
|
|
|
|
@MessagePattern('auth.getUserById')
|
|
getUserById({ id }: { id: string }) {
|
|
return this.authService.getUserById(id);
|
|
}
|
|
|
|
@MessagePattern('auth.getUserBans')
|
|
getUserBans({ user }: { user: UserInfo }) {
|
|
return this.authService.getUserBans(user);
|
|
}
|
|
}
|