35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { Controller, Get, Req, Res, UnauthorizedException, UseGuards } from '@nestjs/common';
|
|
import { OIDCLoginGuard } from '../guards/authentik-auth.guard';
|
|
import { Request, Response } from 'express';
|
|
import { UsersService } from 'src/identity-and-account/users-management/services/users.service';
|
|
import { Access } from 'src/common/decorators/module-access.decorators';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(
|
|
private readonly usersService: UsersService,
|
|
){}
|
|
|
|
@UseGuards(OIDCLoginGuard)
|
|
@Get('/v1/login')
|
|
login() { }
|
|
|
|
@Get('/callback')
|
|
@UseGuards(OIDCLoginGuard)
|
|
loginCallback(@Req() req: Request, @Res() res: Response) {
|
|
// res.redirect("http://10.100.251.2:9013/#/v1/login-success");
|
|
res.redirect(process.env.REDIRECT_URL_DEV!);
|
|
}
|
|
|
|
@Get('/me')
|
|
async getProfile(
|
|
@Access('email') email: string,
|
|
@Req() req: Request) {
|
|
if (!req.user) {
|
|
throw new UnauthorizedException('Not logged in');
|
|
}
|
|
return this.usersService.findOneByEmail(email);
|
|
}
|
|
|
|
}
|