AWS Lambda fronted by httpAPI Gateway not Working ...
# support-questions-legacy
e
AWS Lambda fronted by httpAPI Gateway not Working But dev computer backend Does For OTP, both lambda and backend send OTP but providing OTP value in UI results in OTP remaining. No error message or reason given. The code for both Lambda Handler and backend are based on docs and the same. Issue seems to be this:
Copy code
// For lambda fronted by httpAPI Gateway
...
logger.js:31 com.supertokens {message: "saveTokensFromHeaders: Saving updated tokens from the response headers", supertokens-website-ver: "17.0.0"}
logger.js:31 com.supertokens {message: "fireSessionUpdateEventsIfNecessary returning early because the front token was not updated", supertokens-website-ver: "17.0.0"}
Copy code
// For local dev computer backend
logger.js:31 com.supertokens { message: "saveTokensFromHeaders: Saving updated tokens from the response headers", supertokens-website-ver: "17.0.0"}
logger.js:31 com.supertokens { message: "saveTokensFromHeaders: Setting sFrontToken: {long token}", supertokens-website-ver: "17.0.0"}
The line of code that has a different is in saveTokensFromHeaders (see https://github.com/supertokens/supertokens-website/blob/469421261802a73ca7439e9de039e7d56e53ca9d/lib/build/xmlhttprequest.js#L815)
Copy code
// frontToken has a value with backend, but no value with lambda fronted by httpAPI Gateway
frontToken = response.headers.get("front-token");
It feels like the
front-token
HEADER is not getting returned by the lambda fronted by httpAPI Gateway. 2.5 days of trying to figrue this out. Any ideas?
r
hey @erichosick have you set isServerlessEnv: true in the supertokens.init on the backend?
e
Copy code
export const SuperTokensConfig = {
  framework: 'awsLambda',
  supertokens: {
    // These are the connection details of the app created on supertokens.com
    connectionURI: env.superTokenAppUrl,
    apiKey: env.superTokenAppApiKey,
  },
  appInfo: {
    // learn more about this on https://supertokens.com/docs/passwordless/appinfo
    appName: 'Qloogle',
    apiDomain: getApiDomain(),
    websiteDomain: getWebsiteDomain(),
    apiBasePath: '/auth',
    websiteBasePath: '/',
    apiGatewayPath: '/',
  },
  // recipeList contains all the modules that you want to use from SuperTokens.
  // See the full list here: https://supertokens.com/docs/guides
  recipeList: [
    Passwordless.init({
      contactMethod: 'EMAIL',
      flowType: 'USER_INPUT_CODE',
    }),
    Session.init(),
    Dashboard.init(),
    UserRoles.init(),
    UserMetadata.init(),
  ],
  isInServerlessEnv: true,
};
I think so, ya.
r
can you enable backend debug logs and show the output when calling the API where you type in the OTP?
e
OTP Step Part 01
Copy code
START
2023-07-02 22:10:41.654 INFO    undefined
2023-07-02 22:10:41.654 INFO    undefined
2023-07-02 22:10:41.654 INFO    undefined
2023-07-03T05:10:41.653Z com.supertokens {t: "2023-07-03T05:10:41.653Z", message: "middleware: Started", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.654Z com.supertokens {t: "2023-07-03T05:10:41.654Z", message: "middleware: requestRID is: passwordless", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.654Z com.supertokens {t: "2023-07-03T05:10:41.654Z", message: "middleware: Checking recipe ID for match: passwordless", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-02 22:10:41.655 INFO    undefined
2023-07-02 22:10:41.655 INFO    undefined
2023-07-03T05:10:41.655Z com.supertokens {t: "2023-07-03T05:10:41.654Z", message: "middleware: Matched with recipe ID: passwordless", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.655Z com.supertokens {t: "2023-07-03T05:10:41.655Z", message: "middleware: Request being handled by recipe. ID is: /signinup/code/consume", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-02 22:10:41.709 INFO    undefined
2023-07-03T05:10:41.709Z com.supertokens {t: "2023-07-03T05:10:41.709Z", message: "createNewSession: Started", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-02 22:10:41.710 INFO    undefined
2023-07-03T05:10:41.710Z com.supertokens {t: "2023-07-03T05:10:41.709Z", message: "createNewSession: Wrapping done", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
OTP Step Part 02
Copy code
2023-07-02 22:10:41.749 INFO    undefined
2023-07-02 22:10:41.749 INFO    undefined
2023-07-02 22:10:41.749 INFO    undefined
2023-07-03T05:10:41.749Z com.supertokens {t: "2023-07-03T05:10:41.749Z", message: "createNewSession: Access token payload built", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.749Z com.supertokens {t: "2023-07-03T05:10:41.749Z", message: "createNewSession: using transfer method cookie", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.749Z com.supertokens {t: "2023-07-03T05:10:41.749Z", message: "createNewSession: Started", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-02 22:10:41.769 INFO    undefined
2023-07-02 22:10:41.769 INFO    undefined
2023-07-03T05:10:41.769Z com.supertokens {t: "2023-07-03T05:10:41.769Z", message: "createNewSession: Finished", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.769Z com.supertokens {t: "2023-07-03T05:10:41.769Z", message: "parseJWTWithoutSignatureVerification: version from header: 3", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
OTP Step Part 03
Copy code
2023-07-02 22:10:41.770 INFO    undefined
2023-07-02 22:10:41.770 INFO    undefined
2023-07-02 22:10:41.770 INFO    undefined
2023-07-03T05:10:41.770Z com.supertokens {t: "2023-07-03T05:10:41.770Z", message: "createNewSession: Session created in core built", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.770Z com.supertokens {t: "2023-07-03T05:10:41.770Z", message: "createNewSession: Cleared old tokens", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.770Z com.supertokens {t: "2023-07-03T05:10:41.770Z", message: "setToken: Setting access token as cookie", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-02 22:10:41.773 INFO    undefined
2023-07-02 22:10:41.773 INFO    undefined
2023-07-02 22:10:41.773 INFO    undefined
2023-07-02 22:10:41.773 INFO    undefined
2023-07-03T05:10:41.773Z com.supertokens {t: "2023-07-03T05:10:41.773Z", message: "setToken: Setting refresh token as cookie", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.773Z com.supertokens {t: "2023-07-03T05:10:41.773Z", message: "createNewSession: Attached new tokens to res", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.773Z com.supertokens {t: "2023-07-03T05:10:41.773Z", message: "Sending response to client with status code: 200", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
2023-07-03T05:10:41.773Z com.supertokens {t: "2023-07-03T05:10:41.773Z", message: "middleware: Ended", file: "/var/task/src/functions/auth/handler.js:9942:25" sdkVer: "14.1.2"}
END Duration: 155.42 ms Memory Used: 111 MB
I also have the email step too if you need it.
And thank you so much for helping on this.
The handler:
Copy code
import supertokens from "supertokens-node";
import { middleware } from "supertokens-node/framework/awsLambda";
import SuperTokensConfig from './supertoken-backend-config';
import middy from "@middy/core";
import cors from "@middy/http-cors";
import env from './env-backend-config';

supertokens.init(SuperTokensConfig);

const postAuth = middy(middleware()).use(cors({
  origin: env.reactAppWebsiteUrlDomain,
  credentials: true,
  headers: ["Content-Type", ...supertokens.getAllCORSHeaders()].join(", "),
  methods: "OPTIONS,POST,GET,PUT,DELETE"
})).onError(request => {
  throw request.error;
});

export default postAuth;
r
whats the request and response body and header of the consume API call?
can you scroll further down in the headers and show me the full value?
e
Response Body:
Copy code
{
    "status": "OK",
    "createdNewUser": false,
    "user": {
        "email": "{the email}",
        "id": "b95499f7-06df-49cd-acbd-829d96187b19",
        "timeJoined": 1686781
141650
    }
}
Is it a case-sensitive issue? frontToken = headers.get("front-token");
r
right so this does seem to be fine. Is the session not being saved when you get this response?
casing shouldn't matter
e
The response (from working backend):
Copy code
{
  "status": "OK",
  "createdNewUser": false,
  "user": {
    "email": "{same user email}",
    "id": "b95499f7-06df-49cd-acbd-829d96187b19",
    "timeJoined": 1686781141650
  }
}
Same case of
Front-Token:
r
what are the cookies stored on the browser before and after attempting to sign in?
not the local backend one. The one that';s not working
e
Ya. I'll do that one next. I run in incognito. One sec.
And again I super appreciate you doing this for us.
r
hmm. This is really, really odd
do you see any error on the browser console?
this is odd
whats the orange triangle next to set-cookie (at the end of it) in the above screenshot?
can you hover on it and see what the message is?
e
I'm hovering over it, but nothing seems to happen. No popup.
r
huh. Thats strange too
can we get on a debugging call? Might be more effecient
e
Sure! That would be so helpful. Thank you.
Can we use discord?
6 Views