bump package version to 1.5.0
[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 * @alias {object} Context
8 */
9
10 /**
11 * @alias {object} HtmlOptions
12 */
13
14 /**
15 * @typedef {import('../session-manager').AppTemplateCallback} AppTemplateCallback
16 */
17
18 /**
19 *
20 * @returns {string[]} section
21 */
22 function mainContent() {
23 return [
24 `<section>
25 \t<a href="./login">Try Again?</a>
26 </section>`,
27 ];
28 }
29
30
31 /**
32 * Render any errors from attempting IndieAuth.
33 * @param {Context} ctx context
34 * @param {object} options options
35 * @param {object} options.manager manager options
36 * @param {string} options.manager.pageTitle page title
37 * @param {object} options.dingus dingus options
38 * @param {string} options.dingus.selfBaseUrl base url
39 * @param {AppTemplateCallback} appCb function to mogrify htmlOptions
40 * @returns {string} page
41 */
42 module.exports = (ctx, options, appCb = () => {}) => {
43 const pagePathLevel = 1;
44 const htmlOptions = {
45 pageIdentifier: 'indieAuthError',
46 pageTitle: options.manager.pageTitle,
47 logoUrl: options.manager.logoUrl,
48 footerEntries: options.manager.footerEntries,
49 errorContent: [
50 '<p>Problems were encountered while trying to authenticate your profile URL.</p>',
51 ],
52 };
53 appCb(pagePathLevel, ctx, htmlOptions);
54 sessionNavLinks(pagePathLevel, ctx, htmlOptions);
55
56 // Ensure there is always an error to report, even if we do not have one, as we ended up here somehow.
57 if (!ctx?.errors?.length) {
58 ctx.errors = [
59 'Unknown Error &mdash; we are not sure what just happened',
60 ];
61 }
62 return th.htmlPage(pagePathLevel, ctx, htmlOptions, mainContent());
63 };