mirror of
https://github.com/PeterMaquiran/tvone-api.git
synced 2026-04-18 08:17:52 +00:00
36 lines
877 B
TypeScript
36 lines
877 B
TypeScript
import { KeycloakAuthGuard } from '../auth/keycloak.guard';
|
|
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
|
|
import type { User } from '@prisma/client';
|
|
import type { 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 {
|
|
@UseGuards(KeycloakAuthGuard, UserProvisioningGuard)
|
|
@Get()
|
|
getProfile(@Req() req: ProfileRequest) {
|
|
const kc = req.user;
|
|
return {
|
|
keycloak: {
|
|
email: kc.email,
|
|
name: kc.name,
|
|
picture: kc.picture,
|
|
email_verified: kc.email_verified,
|
|
roles: kc.roles,
|
|
},
|
|
user: req.dbUser,
|
|
};
|
|
}
|
|
}
|