Comments (8)
Hey, it's working. I just updated the dependencies with exact version as in the package.json of the tutorial-repo.
Thanks @adrien2p
from medusa-extender.
Hi there,
Could you show me your components where you are trying to access the loggedInUser. Also, i can see that you are applying it everywhere. The store routes have an optional auth system which means than the loggedInUser can be undefined.
I suggest you to look at this you can see here that the loggedInUser will always be part of the container but can be null in some cases
from medusa-extender.
I tried by installing the medusa-marketplace package as well.
Main error was occurring while trying to add a product.
This is my product.service.ts
import {
EntityEventType,
MedusaEventHandlerParams,
OnMedusaEntityEvent,
Service,
} from "medusa-extender";
import { EntityManager } from "typeorm";
import { ProductService as MedusaProductService } from "@medusajs/medusa/dist/services";
import { Product } from "./product.entity";
import { User } from "../user/user.entity";
import UserService from "../user/user.service";
type ConstructorParams = {
manager: any;
loggedInUser: User;
productRepository: any;
productVariantRepository: any;
productOptionRepository: any;
eventBusService: any;
productVariantService: any;
productCollectionService: any;
productTypeRepository: any;
productTagRepository: any;
imageRepository: any;
searchService: any;
userService: UserService;
cartRepository: any;
priceSelectionStrategy: any;
};
@Service({ scope: "SCOPED", override: MedusaProductService })
export class ProductService extends MedusaProductService {
readonly #manager: EntityManager;
constructor(private readonly container: ConstructorParams) {
super(container);
this.#manager = container.manager;
}
@OnMedusaEntityEvent.Before.Insert(Product, { async: true })
public async attachStoreToProduct(
params: MedusaEventHandlerParams<Product, "Insert">
): Promise<EntityEventType<Product, "Insert">> {
const { event } = params;
const loggedInUser = this.container.loggedInUser;
event.entity.store_id = loggedInUser.store_id; // getting loggedInUser as null
return event;
}
prepareListQuery_(selector: object, config: object): object {
const loggedInUser = this.container.loggedInUser;
if (loggedInUser) {
selector["store_id"] = loggedInUser.store_id;
}
return super.prepareListQuery_(selector, config);
}
}
from medusa-extender.
So, as you can see in the tutorial, we now always register the loggedInUser but as a nullable value instead of registering it only when there is a loggedInUser. Can I ask you to update your middleware with the one in the tutorial repo?
from medusa-extender.
I replaced the modules folder from the tutorial-repo but getting same error again. Not sure what is happening.
error: Cannot read properties of null (reading 'store_id')
TypeError: Cannot read properties of null (reading 'store_id')
from medusa-extender.
could you share me a reproducible repo so that I can see the config as well as the code please
from medusa-extender.
Hi @adrien2p I have exactly the same problem. I do not want to downgrade the medusa's version tho. Is there any documentation on how and where req.user is resolved from a request?
Here are the versions of the packages used
"@medusajs/medusa": "1.3.5",
"@medusajs/medusa-cli": "1.3.1",
"medusa-extender": "1.7.4",
from medusa-extender.
Hi @adrien2p I have exactly the same problem. I do not want to downgrade the medusa's version tho. Is there any documentation on how and where req.user is resolved from a request?
Here are the versions of the packages used "@medusajs/medusa": "1.3.5", "@medusajs/medusa-cli": "1.3.1", "medusa-extender": "1.7.4",
I ended up fixing it by
if (req.user && req.user.userId) {
userId = req.user.userId;
} else if (req.session.jwt) {
const decoded = jwt_decode(req.session.jwt);
userId = decoded['userId'];
}
if (userId) {
const userService = req.scope.resolve('userService') as UserService;
const loggedInUser = await userService.retrieve(userId, {
select: ['id', 'store_id'],
});
req.scope.register({
loggedInUser: {
resolve: () => loggedInUser,
},
});
}
from medusa-extender.
Related Issues (20)
- medusa develop command does not work with medusa-extender[BUG] HOT 3
- Update documentation for the new decorators
- [BUG] Middleware not working as expected for Loggedin User HOT 1
- Typo in documentation
- [BUG] store routes requiredAuth does not work. HOT 3
- MetadataReader comprehensive error message HOT 5
- [BUG] Migrate command --show
- DOC: Add use case for the extender HOT 3
- [BUG] Multitenancy Config | Tenant Code Resolver HOT 3
- Fix documentation
- medusa-auth-plugin not working with 1.8.8 extender HOT 6
- Overwriting existing column of entity HOT 1
- Cors Issue - setting of cors address HOT 1
- [BUG] Medusa Server not starting after adding medusa-extender to existing project HOT 4
- [BUG] Middleware is not working HOT 1
- Compatible with Medusa 1.8? HOT 1
- [BUG] : Cannot run extender from the cloned server starter
- [BUG] Unable to Intsall extender on latest Medusa HOT 1
- Wow, when I saw this project, I felt excited. HOT 5
- Not working with medusa js 1.3.16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from medusa-extender.