diff --git a/src/env.ts b/src/env.ts index 8ff6ff7..657a14b 100644 --- a/src/env.ts +++ b/src/env.ts @@ -31,10 +31,6 @@ appSigner.getPubkey().then(pubkey => { console.log(`Running as ${pubkey}`) }) -netContext.pool.get = (url: string) => { - throw new Error('Attempted to use default pool') -} - routerContext.getDefaultRelays = always(DEFAULT_RELAYS) routerContext.getIndexerRelays = always(INDEXER_RELAYS) routerContext.getSearchRelays = always(SEARCH_RELAYS) diff --git a/src/server.ts b/src/server.ts index b5d73a1..335ff3a 100644 --- a/src/server.ts +++ b/src/server.ts @@ -4,7 +4,7 @@ import rateLimit from 'express-rate-limit' import { appSigner } from './env.js' import { render } from './templates.js' import { confirmSubscriptionAction, unsubscribeAction, registerSubscription, ActionError } from './actions.js' -import { getSubscriptionById, insertEvent, getSubscriptionByKey } from './database.js' +import { getSubscriptionById, insertEvent, getSubscriptionByKey, getSubscriptionByPubkey } from './database.js' import { load } from '@welshman/net' import { getIdFilters } from '@welshman/util' @@ -81,8 +81,11 @@ addRoute('post', '/subscription/email', async (req: Request, res: Response) => { res.json(result) } catch (error: any) { // If the error is just Postmark failing, the subscription was still created - if (error.message?.includes('APIKey')) { - res.json({ key: 'fallback', callback: `${process.env.BASE_URL}/notify/fallback` }) + // Look up the actual subscription key from the DB + const sub = await getSubscriptionByPubkey(pubkey) + if (sub) { + const callback = `${process.env.BASE_URL}/notify/${sub.id}` + res.json({ key: sub.key, callback }) } else { console.error('Failed to register subscription:', error) res.status(500).json({ error: 'Failed to register subscription' }) @@ -180,7 +183,7 @@ addRoute('get', '/unsubscribe', async (req: Request, res: Response) => { // pass } - res.send(await render('pages/unsubscribe-success.html')) + res.send(await render('pages/unsubscribe.html')) }) server.use((err: Error, req: Request, res: Response, next: NextFunction) => {