Skip to content

Commit

Permalink
Always provide a user id to logged in pages #3263
Browse files Browse the repository at this point in the history
  • Loading branch information
LinaKind committed May 23, 2024
1 parent e1a702b commit f00d48d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
22 changes: 8 additions & 14 deletions src/http/page-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { detectClientClassification } from './detect-client-classification';
import { sendHtmlResponse } from './send-html-response';
import { sendRedirect } from './send-redirect';
import { constructHtmlResponse } from '../read-side/html-pages/construct-html-response';
import { ConstructPage } from '../read-side/html-pages/construct-page';
import { ConstructLoggedInPage, ConstructPage } from '../read-side/html-pages/construct-page';
import { HtmlPage } from '../read-side/html-pages/html-page';
import { PageLayout } from '../read-side/html-pages/page-layout';
import { standardPageLayout } from '../read-side/html-pages/shared-components/standard-page-layout';
Expand Down Expand Up @@ -72,7 +72,7 @@ export const pageHandler = (

export const pageHandlerWithLoggedInUser = (
dependencies: GetLoggedInScietyUserDependencies,
handler: ConstructPage,
handler: ConstructLoggedInPage,
pageLayout: PageLayout = standardPageLayout,
): Middleware => async (context, next) => {
const loggedInUser = getLoggedInScietyUser(dependencies, context);
Expand All @@ -87,19 +87,13 @@ export const pageHandlerWithLoggedInUser = (
...context.state,
},
(partialParams) => pipe(
getLoggedInScietyUser(dependencies, context),
O.matchW(
() => ({
...partialParams,
user: undefined,
}),
(user) => ({
...partialParams,
user,
}),
),
loggedInUser.value,
(user) => ({
...partialParams,
user,
}),
),
handler,
handler(loggedInUser.value.id),
)();
if (E.isRight(input)) {
constructAndSendHtmlResponse(dependencies, pageLayout, context)(E.right(input.right));
Expand Down
5 changes: 5 additions & 0 deletions src/read-side/html-pages/construct-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as TE from 'fp-ts/TaskEither';
import { HtmlPage } from './html-page';
import { RedirectTarget } from './redirect-target';
import { ErrorPageBodyViewModel } from '../../types/error-page-body-view-model';
import { UserId } from '../../types/user-id';

export type ConstructPage = (
params: Record<string, unknown>,
) => TE.TaskEither<ErrorPageBodyViewModel | RedirectTarget, HtmlPage>;

export type ConstructLoggedInPage = (userId: UserId) => (
params: Record<string, unknown>,
) => TE.TaskEither<ErrorPageBodyViewModel | RedirectTarget, HtmlPage>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { constructViewModel } from './construct-view-model';
import { Dependencies } from './dependencies';
import { paramsCodec } from './params';
import { renderAsHtml } from './render-as-html';
import { ConstructPage } from '../../construct-page';
import { ConstructLoggedInPage } from '../../construct-page';
import { toNotFound } from '../../create-page-from-params';

export const page = (
dependencies: Dependencies,
): ConstructPage => (input) => pipe(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
): ConstructLoggedInPage => (userId) => (input) => pipe(
input,
paramsCodec.decode,
E.mapLeft((errors) => {
Expand Down

0 comments on commit f00d48d

Please sign in to comment.