https://supertokens.com/ logo
t

TechnoWill

03/27/2022, 4:59 PM
Does anyone know why all my api requests are hitting a 500 on NextJS, and my custom instance supertokens container isn't logging any requests?
r

rp

03/27/2022, 5:01 PM
Even your application APis? Or just supertokens related APIs?
t

TechnoWill

03/27/2022, 5:02 PM
Just the supertokens related APIs
r

rp

03/27/2022, 5:04 PM
Can I see the code for how you have used the supertokens-node middleware function?
t

TechnoWill

03/27/2022, 5:05 PM
src/pages/api/auth/[[...path]].ts
Copy code
import { superTokensNextWrapper } from "supertokens-node/nextjs";
import { middleware } from "supertokens-node/framework/express";
import { NextApiRequest, NextApiResponse } from "next";
import { Request, Response } from "express";
import supertokens from "supertokens-node";
import { backendConfig } from "../../../config/backendConfig";

supertokens.init(backendConfig() as any);

export default async function superTokens(
  req: NextApiRequest & Request,
  res: NextApiResponse & Response
) {
  await superTokensNextWrapper(
    async (next) => {
      await middleware()(req, res, next);
    },
    req,
    res
  );
  if (!res.writableEnded) {
    res.status(404).send("Not found");
  }
}
r

rp

03/27/2022, 5:05 PM
Alright. Can you surround the whole thing with try and catch and print out the exception?
t

TechnoWill

03/27/2022, 5:07 PM
Copy code
event - compiled client and server successfully in 586 ms (292 modules)
wait  - compiling /auth/[[...path]] (client and server)...
event - compiled client and server successfully in 162 ms (304 modules)
wait  - compiling /api/auth/[[...path]]...
event - compiled client and server successfully in 156 ms (320 modules)
error - Error: [object Object]
wait  - compiling /_error (client and server)...
event - compiled client and server successfully in 75 ms (321 modules)
error - Error: [object Object]
- for the record does the same logs without the try/catch
r

rp

03/27/2022, 5:08 PM
Hmm. Is there anyway you see what
[object Object]
is?
t

TechnoWill

03/27/2022, 5:08 PM
That's what I've been looking at - no idea where's throwing it or where's logging it
r

rp

03/27/2022, 5:09 PM
Hmm. Do a try catch just around
await middleware()(req, res, next);
t

TechnoWill

03/27/2022, 5:11 PM
Nothing - I'm going to try commenting out the whole function and just putting a test log at the start - I have a hunch
r

rp

03/27/2022, 5:11 PM
ok good idea
t

TechnoWill

03/27/2022, 5:13 PM
Ah got it - there's a problem with my config throwing an error
r

rp

03/27/2022, 5:13 PM
ok great!
t

TechnoWill

03/27/2022, 5:15 PM
All working, thanks!
p

philo

03/28/2022, 2:06 PM
You’re processing portion