Skip to content

Commit

Permalink
Validate profileType, move types
Browse files Browse the repository at this point in the history
  • Loading branch information
timvanoostrom authored and RoanPaulus committed Dec 19, 2024
1 parent e785028 commit 971e5b4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/mijnamsterdam.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ type ReturnTypeAsync<T extends (...args: any) => any> = T extends (
? R
: any;

type ProfileType = 'private' | 'private-attributes' | 'commercial';

type AuthMethod = 'digid' | 'eherkenning';

type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

type Prettify<T> = {
Expand Down
5 changes: 5 additions & 0 deletions src/server/auth/auth-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from './auth-types';
import { FeatureToggle } from '../../universal/config/feature-toggles';
import { AppRoutes } from '../../universal/config/routes';
import { PROFILE_TYPES } from '../../universal/types/App.types';
import { ExternalConsumerEndpoints } from '../routing/bff-routes';
import { generateFullApiUrlBFF } from '../routing/route-helpers';
import { captureException } from '../services/monitoring';
Expand Down Expand Up @@ -172,3 +173,7 @@ export function createLogoutHandler(
return res.redirect(postLogoutRedirectUrl);
};
}

export function isValidProfileType(profileType: unknown) {
return PROFILE_TYPES.includes(profileType as ProfileType);
}
8 changes: 6 additions & 2 deletions src/server/services/cms-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../../universal/helpers/api';
import { hash } from '../../universal/helpers/utils';
import { LinkProps } from '../../universal/types/App.types';
import { isValidProfileType } from '../auth/auth-helpers';
import FileCache from '../helpers/file-cache';
import { getApiConfig } from '../helpers/source-api-helpers';
import { requestData } from '../helpers/source-api-request';
Expand Down Expand Up @@ -285,10 +286,13 @@ async function fetchCmsBase(
query?: QueryParamsCMSFooter
) {
const forceRenew = query?.forceRenew === 'true';

const profileType =
query?.profileType && isValidProfileType(query?.profileType)
? query.profileType
: undefined;
const generalInfoPageRequest = getGeneralPage(
requestID,
query?.profileType,
profileType,
forceRenew
);

Expand Down
13 changes: 13 additions & 0 deletions src/universal/types/App.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,16 @@ export interface Match {
path: string;
url: string;
}

export const PROFILE_TYPES = [
'private',
'commercial',
'private-attributes',
] as const;

export const AUTH_METHODS = ['eherkenning', 'digid'] as const;

declare global {
type ProfileType = (typeof PROFILE_TYPES)[number];
type AuthMethod = (typeof AUTH_METHODS)[number];
}

0 comments on commit 971e5b4

Please sign in to comment.