@ladjs/web 15.0.0 → 16.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +30 -0
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -342,6 +342,36 @@ class Web {
342
342
  const stateHelper = new StateHelper(this.config.views.locals);
343
343
  app.use(stateHelper.middleware);
344
344
 
345
+ // add specific locals
346
+ app.use((ctx, next) => {
347
+ // passport-related helpers (e.g. for rendering log in with X buttons)
348
+ ctx.state.passport = ctx.passport ? {} : false;
349
+ if (
350
+ ctx.passport &&
351
+ ctx.passport.config &&
352
+ ctx.passport.config.providers
353
+ ) {
354
+ for (const key of Object.keys(ctx.passport.config.providers)) {
355
+ ctx.state.passport[key] = boolean(ctx.passport.config.providers[key]);
356
+ }
357
+ }
358
+
359
+ // add limited `ctx` object to the state for views
360
+ ctx.state.ctx = {};
361
+ ctx.state.ctx.get = ctx.get;
362
+ ctx.state.ctx.locale = ctx.locale;
363
+ ctx.state.ctx.params = ctx.params;
364
+ ctx.state.ctx.path = ctx.path;
365
+ ctx.state.ctx.pathWithoutLocale = ctx.pathWithoutLocale;
366
+ ctx.state.ctx.query = ctx.query;
367
+ ctx.state.ctx.session = ctx.session;
368
+ ctx.state.ctx.sessionId = ctx.sessionId;
369
+ ctx.state.ctx.translate = ctx.translate;
370
+ ctx.state.ctx.url = ctx.url;
371
+
372
+ return next();
373
+ });
374
+
345
375
  // session store
346
376
  app.keys = this.config.sessionKeys;
347
377
  app.use(async (ctx, next) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ladjs/web",
3
3
  "description": "Web server for Lad",
4
- "version": "15.0.0",
4
+ "version": "16.0.0",
5
5
  "author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/ladjs/web/issues",
@@ -20,7 +20,7 @@
20
20
  "@ladjs/koa-simple-ratelimit": "^3.0.0",
21
21
  "@ladjs/redis": "^1.0.7",
22
22
  "@ladjs/shared-config": "^7.0.3",
23
- "@ladjs/state-helper": "^1.0.0",
23
+ "@ladjs/state-helper": "^2.0.0",
24
24
  "@ladjs/store-ip-address": "^0.0.7",
25
25
  "boolean": "^3.2.0",
26
26
  "cabin": "^9.1.2",