mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 23:57:32 +00:00
Wip
This commit is contained in:
parent
410c0cef76
commit
de2ed2bfa4
@ -0,0 +1,9 @@
|
||||
const { requestContext } = require('@strapi/strapi');
|
||||
|
||||
module.exports = {
|
||||
beforeCreate() {
|
||||
const store = requestContext.getStore();
|
||||
|
||||
console.log('User info in service: ', store.auth);
|
||||
},
|
||||
};
|
||||
@ -5,7 +5,7 @@ const { createCoreRouter } = require('@strapi/strapi').factories;
|
||||
module.exports = createCoreRouter('api::address.address', {
|
||||
config: {
|
||||
find: {
|
||||
auth: false,
|
||||
// auth: false,
|
||||
},
|
||||
},
|
||||
only: ['find', 'findOne'],
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
const Strapi = require('./Strapi');
|
||||
|
||||
Strapi.factories = require('./factories');
|
||||
Strapi.requestContext = require('./services/request-context');
|
||||
Strapi.compile = require('./compile');
|
||||
|
||||
module.exports = Strapi;
|
||||
|
||||
@ -4,6 +4,7 @@ const { strict: assert } = require('assert');
|
||||
const { has, prop } = require('lodash/fp');
|
||||
|
||||
const { UnauthorizedError } = require('@strapi/utils').errors;
|
||||
const requestCtx = require('../request-context');
|
||||
|
||||
const INVALID_STRATEGY_MSG =
|
||||
'Invalid auth strategy. Expecting an object with properties {name: string, authenticate: function, verify: function}';
|
||||
@ -60,6 +61,9 @@ const createAuthentication = () => {
|
||||
credentials,
|
||||
};
|
||||
|
||||
const store = requestCtx.getStore();
|
||||
store.auth = ctx.state.auth;
|
||||
|
||||
return next();
|
||||
}
|
||||
}
|
||||
|
||||
5
packages/core/strapi/lib/services/request-context.js
Normal file
5
packages/core/strapi/lib/services/request-context.js
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { AsyncLocalStorage } = require('async_hooks');
|
||||
|
||||
module.exports = new AsyncLocalStorage();
|
||||
@ -9,6 +9,7 @@ const { createContentAPI } = require('./content-api');
|
||||
const registerAllRoutes = require('./register-routes');
|
||||
const registerApplicationMiddlewares = require('./register-middlewares');
|
||||
const createKoaApp = require('./koa');
|
||||
const requestCtx = require('../request-context');
|
||||
|
||||
const healthCheck = async (ctx) => {
|
||||
ctx.set('strapi', 'You are so French!');
|
||||
@ -33,6 +34,20 @@ const createServer = (strapi) => {
|
||||
keys: strapi.config.get('server.app.keys'),
|
||||
});
|
||||
|
||||
app.use(async (ctx, next) => {
|
||||
const store = {
|
||||
foo: 'bar',
|
||||
};
|
||||
|
||||
// TODO: handle errors
|
||||
await new Promise((res) => {
|
||||
requestCtx.run(store, async () => {
|
||||
await next();
|
||||
res();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const router = new Router();
|
||||
|
||||
const routeManager = createRouteManager(strapi);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user