mirror of
https://github.com/PeterMaquiran/tvone-api.git
synced 2026-04-18 16:27:51 +00:00
add moodules
This commit is contained in:
@@ -1,24 +1,35 @@
|
||||
import { KeycloakAuthGuard } from '../auth/keycloak.guard';
|
||||
import { ProfileService } from './profile.service';
|
||||
import { Controller, Get, UseGuards, Request } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { User } from '@prisma/client';
|
||||
import { Request } from 'express';
|
||||
import { UserProvisioningGuard } from '../users/user-provisioning.guard';
|
||||
|
||||
type ProfileRequest = Request & {
|
||||
user: {
|
||||
email?: string;
|
||||
name?: string;
|
||||
picture?: string;
|
||||
email_verified?: boolean;
|
||||
roles: string[];
|
||||
};
|
||||
dbUser?: User;
|
||||
};
|
||||
|
||||
@Controller('profile')
|
||||
export class ProfileController {
|
||||
constructor(private readonly profileService: ProfileService) {}
|
||||
|
||||
@UseGuards(AuthGuard('keycloak'))
|
||||
@UseGuards(KeycloakAuthGuard, UserProvisioningGuard)
|
||||
@Get()
|
||||
getProfile(@Request() req) {
|
||||
// The 'user' object here is exactly what you returned from validate()
|
||||
|
||||
getProfile(@Request() req: ProfileRequest) {
|
||||
const kc = req.user;
|
||||
return {
|
||||
email: req.user.email,
|
||||
name: req.user.name,
|
||||
picture: req.user.picture,
|
||||
email_verified: req.user.email_verified,
|
||||
roles: req.user.roles,
|
||||
keycloak: {
|
||||
email: kc.email,
|
||||
name: kc.name,
|
||||
picture: kc.picture,
|
||||
email_verified: kc.email_verified,
|
||||
roles: kc.roles,
|
||||
},
|
||||
user: req.dbUser,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user