Skip to content

Commit 6f53122

Browse files
committed
Fix verify email misused promises
1 parent 52c9d1f commit 6f53122

File tree

7 files changed

+22
-11
lines changed

7 files changed

+22
-11
lines changed

src/authentication/verify-email/landing-page.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const invalidLink = () => oopsPage(
1818
<a href=/me>homepage</a>.`
1919
);
2020

21-
export const verificationSuccessful = pipe(
21+
const verificationSuccessful = pipe(
2222
html`
2323
<div class="container">
2424
<div class="max-w-md mx-auto">
@@ -48,14 +48,15 @@ export const verificationSuccessful = pipe(
4848

4949
export const landing =
5050
(deps: Dependencies, conf: Config) =>
51-
async (req: Request, res: Response<CompleteHtmlDocument>) => {
51+
async (req: Request, res: Response<CompleteHtmlDocument>): Promise<void> => {
5252
const decoded = decodeEmailVerificationLink(deps.logger, conf)(req);
5353
if (E.isLeft(decoded)) {
5454
deps.logger.error(
5555
decoded.left,
5656
'Failed to decode verification link'
5757
);
58-
return res.send(invalidLink());
58+
res.send(invalidLink());
59+
return;
5960
}
6061
const resource = verifyEmail.resource(decoded.right);
6162
const resourceEvents = await deps.getResourceEvents(resource)();
@@ -64,7 +65,8 @@ export const landing =
6465
resourceEvents.left,
6566
'Failed to get resource events for email verification link'
6667
);
67-
return res.send(invalidLink());
68+
res.send(invalidLink());
69+
return;
6870
}
6971

7072
// Note that we don't need to check isAuthorized here because we are authorised
@@ -85,9 +87,11 @@ export const landing =
8587
commitEvent.left,
8688
'Failed to commit verification link event'
8789
);
88-
return res.send(invalidLink());
90+
res.send(invalidLink());
91+
return;
8992
}
9093
}
9194
deps.logger.info(`Successfully verified email %o`, decoded.right);
92-
return res.send(verificationSuccessful);
95+
res.send(verificationSuccessful);
96+
return;
9397
};

src/authentication/verify-email/routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import {Dependencies} from '../../dependencies';
22
import {Config} from '../../configuration';
33
import {Route, get} from '../../types/route';
44
import {landing} from './landing-page';
5+
import expressAsyncHandler from 'express-async-handler';
56

67
export const routes = (
78
deps: Dependencies,
89
conf: Config
910
): ReadonlyArray<Route> => {
1011
return [
11-
get('/auth/verify-email/landing', landing(deps, conf)),
12+
get('/auth/verify-email/landing', expressAsyncHandler(landing(deps, conf))),
1213
];
1314
};

src/http/api-to-handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import {Command} from '../commands';
44
import expressAsyncHandler from 'express-async-handler';
55
import {flow} from 'fp-ts/lib/function';
66
import {apiPost} from './api-post';
7+
import { Route } from '../types/route';
78

89
export const apiToHandlers =
910
(deps: Dependencies, conf: Config) =>
10-
<C>(noun: string, verb: string, cmd: Command<C>) => [
11+
<C>(noun: string, verb: string, cmd: Command<C>): Route[] => [
1112
{
1213
path: `/api/${noun}/${verb}`,
1314
handler: flow(apiPost, expressAsyncHandler)(deps, conf, cmd),

src/http/command-to-handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import {flow} from 'fp-ts/lib/function';
77
import {formPost} from './form-post';
88
import {formGet} from './form-get';
99
import {apiToHandlers} from './api-to-handlers';
10+
import { Route } from '../types/route';
1011

1112
export const commandToHandlers =
1213
(deps: Dependencies, conf: Config) =>
13-
<C, V>(noun: string, verb: string, cmd: Command<C> & Form<V>) => [
14+
<C, V>(noun: string, verb: string, cmd: Command<C> & Form<V>): Route[] => [
1415
{
1516
path: `/${noun}/${verb}`,
1617
handler: flow(formPost, expressAsyncHandler)(deps, cmd, `/${noun}`),

src/http/email-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {html, CompleteHtmlDocument, safe, sanitizeString} from '../types/html';
1515
import {SendEmail} from '../commands';
1616
import {Config} from '../configuration';
1717
import {isolatedPageTemplate} from '../templates/page-template';
18+
import { Route } from '../types/route';
1819

1920
const getActorFrom = (session: unknown, deps: Dependencies) =>
2021
pipe(
@@ -88,7 +89,7 @@ const emailPost =
8889

8990
export const emailHandler =
9091
(conf: Config, deps: Dependencies) =>
91-
<T>(path: string, command: SendEmail<T>) => ({
92+
<T>(path: string, command: SendEmail<T>): Route => ({
9293
path: `/send-email/${path}`,
9394
handler: flow(emailPost, expressAsyncHandler)(conf, deps, command),
9495
method: 'post' as const,

src/http/query-to-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {Dependencies} from '../dependencies';
33
import * as queries from '../queries';
44
import {flow} from 'fp-ts/lib/function';
55
import {queryGet} from './query-get';
6+
import { Route } from '../types/route';
67

78
export const queryToHandler =
8-
(deps: Dependencies) => (path: string, query: queries.Query) => ({
9+
(deps: Dependencies) => (path: string, query: queries.Query): Route => ({
910
path,
1011
handler: flow(queryGet, expressAsyncHandler)(deps, query),
1112
method: 'get' as const,

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {initDependencies} from './init-dependencies';
1818
import * as libsqlClient from '@libsql/client';
1919
import cookieSession from 'cookie-session';
2020
import {initRoutes} from './routes';
21+
import { startVerifyEmailPubSub } from './authentication/verify-email/start-verify-email-pub-sub';
2122

2223
// Dependencies and Config
2324
const conf = loadConfig();
@@ -62,6 +63,7 @@ setInterval(() => {
6263

6364
// Start application
6465
startMagicLinkEmailPubSub(deps, conf);
66+
startVerifyEmailPubSub(deps, conf);
6567
const server = http.createServer(app);
6668
createTerminus(server);
6769

0 commit comments

Comments
 (0)