support interaction between module and apps for updating templates before rendering
[squeep-authentication-module] / lib / template / ia-html.js
1 'use strict';
2
3 const { TemplateHelper: th } = require('@squeep/html-template-helper');
4 const { sessionNavLinks } = require('./helpers');
5
6 /**
7 *
8 * @returns {String}
9 */
10 function mainContent() {
11 return [
12 `<section>
13 \t<a href="./login">Try Again?</a>
14 </section>`,
15 ];
16 }
17
18 /**
19 * Render any errors from attempting IndieAuth.
20 * @param {Object} ctx
21 * @param {String[]} ctx.errors
22 * @param {Object} options
23 * @param {Object} options.manager
24 * @param {String} options.manager.pageTitle
25 * @param {Object} options.dingus
26 * @param {String} options.dingus.selfBaseUrl
27 * @param {(pagePathLevel, ctx, htmlOptions) => {void}} appCb
28 * @returns {String}
29 */
30 module.exports = (ctx, options, appCb = () => {}) => {
31 const pagePathLevel = 1;
32 const htmlOptions = {
33 pageIdentifier: 'indieAuthError',
34 pageTitle: options.manager.pageTitle,
35 logoUrl: options.manager.logoUrl,
36 footerEntries: options.manager.footerEntries,
37 errorContent: [
38 '<p>Problems were encountered while trying to authenticate your profile URL.</p>',
39 ],
40 };
41 appCb(pagePathLevel, ctx, htmlOptions);
42 sessionNavLinks(pagePathLevel, ctx, htmlOptions);
43
44 // Ensure there is always an error to report, even if we do not have one, as we ended up here somehow.
45 if (!ctx?.errors?.length) {
46 ctx.errors = [
47 'Unknown Error &mdash; we are not sure what just happened',
48 ];
49 }
50 return th.htmlPage(pagePathLevel, ctx, htmlOptions, mainContent());
51 };