#What is the recommended way to debug api requests.

22 messages · Page 1 of 1 (latest)

wind edge
#

I'm currently getting 401 requests whenever i hit localhost:9000/admin/auth with my rest client(insomnia). I;m running everything locally and can see the users in the database. Is there a way to step through the requests and see what is going on internally?

dull hound
#

Are there any errors in the backend console?

wind edge
#

There are no errors in the backend console

dull hound
#

Can you specify what are you actually doing. Which request, what endpoint and params? Some screenshots maybe also

wind edge
dull hound
#

Hmm looks good at first glance. Are you sure the database is seeded?

#

Are you using sqlite or postgres in medusa-config?

wind edge
wind edge
dull hound
#

🤔

#

Only thing that comes to mind is you have seeded postgres database, but maybe you're actually using sqlite in medusa-config which isn't seeded?

#

Does GET http://localhost:9000/store/products return something?

wind edge
#

hmm. That also returns a 401. Now i'm wondering if i misconfigured something

wind edge
#

@dull hound So everything stats returning 401 the moment I add the loggedinuser middleware to the my user module

#
@Middleware({ requireAuth: true, routes: [{ method: "all", path: '*' }] })
export class LoggedInUserMiddleware implements MedusaMiddleware {
    public async consume(req: MedusaAuthenticatedRequest, res: Response, next: NextFunction): Promise<void> {
        if (req.user && req.user.userId) {
            console.log("wtf");
            const userService = req.scope.resolve('userService') as UserService;
            const loggedInUser = await userService.retrieve(req.user.userId, {
                select: ['id', 'store_id'],
            });

            req.scope.register({
                loggedInUser: {
                    resolve: () => loggedInUser,
                },
            });
        }
        next();
    }
}
#

but the endpoints work when change requireAuth to true in the middleware. @broken trench Is this expected behavior?

broken trench
#

Looks like you might have applied a middleware on all the routes no?

#

You should avoid using path *

#

Use path /store/* or /admin/* as just * is reserved for custom domain

#

There is plenty of resolved discussions on those subjects on discord. You light be able to find them as well