fix(auth): fix /me route to properly send user data, now also includes module accesses for user.
This commit is contained in:
parent
e67ed22bad
commit
d9d9de759f
|
|
@ -5,6 +5,7 @@ import { UsersModule } from '../users-management/users.module';
|
||||||
import { AuthController } from './controllers/auth.controller';
|
import { AuthController } from './controllers/auth.controller';
|
||||||
import { AuthentikStrategy } from './strategies/authentik.strategy';
|
import { AuthentikStrategy } from './strategies/authentik.strategy';
|
||||||
import { ExpressSessionSerializer } from './serializers/express-session.serializer';
|
import { ExpressSessionSerializer } from './serializers/express-session.serializer';
|
||||||
|
import { UsersService } from 'src/identity-and-account/users-management/services/users.service';
|
||||||
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
|
|
@ -16,6 +17,7 @@ import { ExpressSessionSerializer } from './serializers/express-session.serializ
|
||||||
AuthentikAuthService,
|
AuthentikAuthService,
|
||||||
AuthentikStrategy,
|
AuthentikStrategy,
|
||||||
ExpressSessionSerializer,
|
ExpressSessionSerializer,
|
||||||
|
UsersService,
|
||||||
],
|
],
|
||||||
exports: [ AuthentikAuthService ],
|
exports: [ AuthentikAuthService ],
|
||||||
controllers: [AuthController],
|
controllers: [AuthController],
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
import { Controller, Get, Req, Res, UnauthorizedException, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Req, Res, UnauthorizedException, UseGuards } from '@nestjs/common';
|
||||||
import { OIDCLoginGuard } from '../guards/authentik-auth.guard';
|
import { OIDCLoginGuard } from '../guards/authentik-auth.guard';
|
||||||
import { Request, Response } from 'express';
|
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')
|
@Controller('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
|
constructor(
|
||||||
|
private readonly usersService: UsersService,
|
||||||
|
){}
|
||||||
|
|
||||||
@UseGuards(OIDCLoginGuard)
|
@UseGuards(OIDCLoginGuard)
|
||||||
@Get('/v1/login')
|
@Get('/v1/login')
|
||||||
|
|
@ -17,11 +22,13 @@ export class AuthController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/me')
|
@Get('/me')
|
||||||
getProfile(@Req() req: Request) {
|
async getProfile(
|
||||||
|
@Access('email') email: string,
|
||||||
|
@Req() req: Request) {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
throw new UnauthorizedException('Not logged in');
|
throw new UnauthorizedException('Not logged in');
|
||||||
}
|
}
|
||||||
return req.user;
|
return this.usersService.findOneByEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ export abstract class AbstractUserService {
|
||||||
|
|
||||||
let module_access: Modules[] = [];
|
let module_access: Modules[] = [];
|
||||||
if (user.user_module_access !== null) module_access = toKeysFromBoolean(user.user_module_access);
|
if (user.user_module_access !== null) module_access = toKeysFromBoolean(user.user_module_access);
|
||||||
|
console.log('module access: ', module_access);
|
||||||
|
|
||||||
const clean_user = {
|
const clean_user = {
|
||||||
first_name: user.first_name,
|
first_name: user.first_name,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user