Skip to content

Commit

Permalink
feat: add endpoint for changing domains
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele committed Jun 21, 2024
1 parent 7007704 commit f8b3589
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/app-api/src/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
UserUpdateDTO,
} from '../service/UserService.js';
import { AuthenticatedRequest, AuthService, LoginOutputDTO } from '../service/AuthService.js';
import { Body, Get, Post, Delete, JsonController, UseBefore, Req, Put, Params, Res } from 'routing-controllers';
import { Body, Get, Post, Delete, JsonController, UseBefore, Req, Put, Params, Res, Param } from 'routing-controllers';
import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi';
import { Type } from 'class-transformer';
import { IdUuidDTO, IdUuidDTOAPI, ParamId, ParamIdAndRoleId } from '../lib/validators.js';
Expand All @@ -18,6 +18,7 @@ import { PERMISSIONS } from '@takaro/auth';
import { RangeFilterCreatedAndUpdatedAt } from './shared.js';
import { DomainOutputDTO, DomainService } from '../service/DomainService.js';
import { TakaroDTO } from '@takaro/util';
import { config } from '../config.js';

export class GetUserDTO {
@Length(3, 50)
Expand Down Expand Up @@ -226,4 +227,21 @@ export class UserController {
const user = await service.inviteUser(data.email);
return apiResponse(user);
}

@UseBefore(AuthService.getAuthMiddleware([], false))
@Post('/user/selected-domain/:domainId')
@OpenAPI({
summary: 'Set the selected domain for the user',
description:
'One user can have multiple domains, this endpoint is a helper to set the selected domain for the user',
})
async setSelectedDomain(@Req() req: AuthenticatedRequest, @Param('domainId') domainId: string) {
req.res?.cookie('takaro-domain', domainId, {
sameSite: config.get('http.domainCookie.sameSite') as boolean | 'strict' | 'lax' | 'none' | undefined,
secure: config.get('http.domainCookie.secure'),
domain: config.get('http.domainCookie.domain'),
});

return apiResponse();
}
}

0 comments on commit f8b3589

Please sign in to comment.