I got 405 when signin/up. I am using NextJS and p...
# support-questions-legacy
y
I got 405 when signin/up. I am using NextJS and passwordless login. (Phone) I have
pages/api/auth/[[...path]].tsx
and it's content is same as doc. This is my appInfo
Copy code
export const appInfo = {
  appName: NAME,
  apiDomain: DOMAIN,
  websiteDomain: DOMAIN,
  apiBasePath: "/api/auth",
  websiteBasePath: "/auth"
}
I can see UI in
<DOMAIN>/auth
, but when I provide phone number and click continue, I got this.
Copy code
[Error] Failed to load resource: the server responded with a status of 405 (Method Not Allowed) (refresh, line 0) <DOMAIN>/api/auth/session/refresh

[Error] Failed to load resource: the server responded with a status of 405 (Method Not Allowed) (refresh, line 0)
<DOMAIN>/api/auth/session/refresh

[Error] Failed to load resource: the server responded with a status of 405 (Method Not Allowed) (refresh, line 0)
<DOMAIN>/api/auth/session/refresh

[Error] Failed to load resource: the server responded with a status of 405 (Method Not Allowed) (code, line 0)
<DOMAIN>/api/auth/signinup/code
r
hey @yujonglee our sdk or services never return a 405. You should check what could be returning 405 on your end.
y
Does
superTokensNextWrapper
handles
session/refresh
and
signinup/code
? I am bit confused because it is clear that I have
/api/auth
route, but not
/api/auth/session/refresh
and
/api/auth/signinup/code
This is my
pages/api/auth/[[...path]].tsx
Copy code
ts
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())

export default async function superTokens(
  req: NextApiRequest & Request,
  res: NextApiResponse & Response
) {
  await superTokensNextWrapper(
    async (next) => {
      // This is needed for production deployments with Vercel
      res.setHeader(
        "Cache-Control",
        "no-cache, no-store, max-age=0, must-revalidate"
      );
      await middleware()(req, res, next)
    },
    req,
    res
  )
  if (!res.writableEnded) {
    res.status(404).send("Not found")
  }
}
r
yes, this does
do a console log on this route, right before
superTokensNextWrapper
and see if it gets logged
y
@rp_st 1. I tried turning Cloudflare Proxy off but it doesn't help. 2. When I look into log, it seems like Supertoken has some problem.
Copy code
TypeError: Cannot read properties of undefined (reading 'split')
    at new SuperTokens (/var/task/node_modules/supertokens-node/lib/build/supertokens.js:370:24)
    at SuperTokensWrapper.init (/var/task/node_modules/supertokens-node/lib/build/supertokens.js:408:36)
    at 2290 (/var/task/.next/server/pages/api/auth/[[...path]].js:97:37)
    at __webpack_require__ (/var/task/.next/server/webpack-api-runtime.js:25:42)
    at __webpack_exec__ (/var/task/.next/server/pages/api/auth/[[...path]].js:145:39)
    at /var/task/.next/server/pages/api/auth/[[...path]].js:146:70
    at __webpack_require__.X (/var/task/.next/server/webpack-api-runtime.js:108:21)
    at /var/task/.next/server/pages/api/auth/[[...path]].js:146:47
    at Object.<anonymous> (/var/task/.next/server/pages/api/auth/[[...path]].js:149:3)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
TypeError: Cannot read properties of undefined (reading 'split')
    at new SuperTokens (/var/task/node_modules/supertokens-node/lib/build/supertokens.js:370:24)
    at SuperTokensWrapper.init (/var/task/node_modules/supertokens-node/lib/build/supertokens.js:408:36)
    at 2290 (/var/task/.next/server/pages/api/auth/[[...path]].js:97:37)
    at __webpack_require__ (/var/task/.next/server/webpack-api-runtime.js:25:42)
    at __webpack_exec__ (/var/task/.next/server/pages/api/auth/[[...path]].js:145:39)
    at /var/task/.next/server/pages/api/auth/[[...path]].js:146:70
    at __webpack_require__.X (/var/task/.next/server/webpack-api-runtime.js:108:21)
    at /var/task/.next/server/pages/api/auth/[[...path]].js:146:47
    at Object.<anonymous> (/var/task/.next/server/pages/api/auth/[[...path]].js:149:3)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
RequestId: e3d16d2c-5438-4b9e-be86-d5fb8d42d225 Error: Runtime exited with error: exit status 1
Runtime.ExitError
r
whats the request that you are making from the frontend?
you can copy the curl comand from the browser and paste it here
y
Copy code
curl 'https://ringup.me/api/auth/session/refresh' \
-X 'POST' \
-H 'Accept: */*' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Host: ringup.me' \
-H 'Origin: https://ringup.me' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15' \
-H 'Referer: https://ringup.me/auth' \
-H 'Content-Length: 0' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'st-auth-mode: cookie' \
-H 'fdi-version: 1.16,1.17' \
-H 'rid: session'
Copy code
curl 'https://ringup.me/api/auth/signinup/code' \
-X 'POST' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Host: ringup.me' \
-H 'Origin: https://ringup.me' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15' \
-H 'Referer: https://ringup.me/auth' \
-H 'Content-Length: 29' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'st-auth-mode: cookie' \
-H 'fdi-version: 1.17' \
-H 'rid: passwordless' \
--data-binary '{"phoneNumber":<MY_NUMBER>}'
r
i think the issue is
--data-binary
how are you sending the request in code?
y
I use built-in UI of Supertoken. (
/auth
) Below is when I hit
continue
in UI.
Copy code
curl 
'https://ringup.me/api/auth/signinup/code' \
-X 'POST' \
-H 'Content-Type: application/json' \
-H 'Accept: */*' \
-H 'Sec-Fetch-Site: same-origin' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Host: ringup.me' \
-H 'Origin: https://ringup.me' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15' \
-H 'Referer: https://ringup.me/auth' \
-H 'Content-Length: 29' \
-H 'Connection: keep-alive' \
-H 'Sec-Fetch-Dest: empty' \
-H 'st-auth-mode: cookie' \
-H 'fdi-version: 1.17' \
-H 'rid: passwordless' \
--data-binary '{"phoneNumber":<MY_NUMBER>}'
r
whats ur backend supertokens.init config? Have you specified a connection uri?
y
Yes, I did.
Copy code
ts

import PasswordlessNode from "supertokens-node/recipe/passwordless"
import SessionNode from "supertokens-node/recipe/session"
import { TwilioService } from "supertokens-node/recipe/passwordless/smsdelivery";
import { TypeInput } from "supertokens-node/types";

import { appInfo } from "./appInfo"

export const backendConfig = (): TypeInput => {
  return {
    framework: "express",
    // supertokens: process.env.MY_ENV === "DEV"
    // ? { connectionURI: "https://try.supertokens.io" }
    // : {
    //   connectionURI: process.env.SUPERTOKENS_CONNECTION_URI!,
    //   apiKey: process.env.SUPERTOKENS_API_KEY!,
    // },
    supertokens: { connectionURI: "https://try.supertokens.io" },
    appInfo,
    recipeList: [
      PasswordlessNode.init({
        flowType: "USER_INPUT_CODE",
        contactMethod: "PHONE",
        smsDelivery: process.env.MY_ENV === "DEV" 
          ? undefined
          : {
            service: new TwilioService({
              twilioSettings: {
                accountSid: process.env.TWILIO_ACCOUNT_SID!,
                authToken: process.env.TWILIO_AUTH_TOKEN!,
                from: process.env.TWILIO_PHONE_NUMBER!,
              },
            }),
          },
        override: {
          functions: (oI: any) => {
            return {
              ...oI,
              signUp: async function (input: any) {
                // First we call the original implementation of signUpPOST.
                const response = await oI.signUp(input);

                // Post sign up response, we check if it was successful
                if (response.status === "OK") {
                  const { id, email } = response.user;
                  // TODO: post sign up logic
                }
                return response;
              }
            }
          }
        }
      }),
      SessionNode.init(),
    ],
    isInServerlessEnv: true,
  }
}
r
are you sure this is the config that's being loaded? You have specified the connectionURI, however, the error indicates that it's not specified..
try clearing all the nextjs cache and rebuilding the app
25 Views