You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ability to create a generic applicationContext which can be used in the app.
This is typically created when you're handling some backend routes (rest, graphql) and you have the graphql context, or express 'request' object but we need to move things outside this layer into application logic.
// in resource for routing
const { AsyncLocalStorage } = require('node:async_hooks');
const asyncLocalStorage = new AsyncLocalStorage();
// can be exported by the package and extended.
export type IApplicationContext = {
user: User
roles: string[],
isLoggedIn: boolean,
}
// you can also add it as a middleware in express
async function createContext(req, res, security: SecurityService): IApplicationContext {
// define the response like user, tenant, roles, etc
}
{
async init(_, { doSomething, security, validator }) {
app.get("/account", async (req, res) => {
await validator.validate(AccountFiltersModel, req.params.filters)
await withContext({}, doSomething, params); // params should be typesafe.
};
}
// and in do something
const context = useContext();
The text was updated successfully, but these errors were encountered:
theodorDiaconu
changed the title
feat: use node runincontext
feat: use node async local storage
Dec 25, 2024
Ability to create a generic applicationContext which can be used in the app.
This is typically created when you're handling some backend routes (rest, graphql) and you have the graphql context, or express 'request' object but we need to move things outside this layer into application logic.
The text was updated successfully, but these errors were encountered: