sammon2412
02/08/2024, 7:22 PMjavascript
import express from "express";
import { verifySession } from "supertokens-node/recipe/session/framework/express";
import { SessionRequest } from "supertokens-node/framework/express";
let app = express();
app.post("/like-comment", verifySession(), (req: SessionRequest, res) => {
let userId = req.session!.getUserId();
//....
});
I've added verifySession()
to ensure that only authenticated users can access the /like-comment
route. However, I'm having trouble accessing this route from the front-end using Axios. I've wrapped my component inside SessionAuth
so that logged-in users have access, but I keep receiving a 401 error.
Could anyone guide me on how to properly access this route from the front-end using Axios and ensure that the user is authenticated?
Thanks in advance!rp_st
02/09/2024, 3:41 AMrp_st
02/09/2024, 3:41 AMsammon2412
02/09/2024, 3:53 PMsammon2412
02/09/2024, 3:57 PMsammon2412
02/09/2024, 4:00 PMhttps://supertokens.com/docs/thirdparty/custom-ui/handling-session-tokens
From this document I understood that , If I called `supertokens.init`then I don't need to do anything while calling APIssammon2412
02/09/2024, 4:15 PMsammon2412
02/09/2024, 4:16 PM401 Unauthorized
sammon2412
02/09/2024, 4:16 PMlogs
[DEBUG] 2024-02-09T15:47:14.092Z 6db5db23-3a68-446f-856d-c8859a687f1b
{
"t": "2024-02-09T15:47:14.092Z",
"sdkVer": "0.18.7",
"message": "errorHandler: Error is from SuperTokens recipe. Message: Session does not exist. Are you sending the session tokens in the request with the appropriate token transfer method?",
"file": "supertokens.py:662"
}
rp_st
02/09/2024, 4:24 PMrp_st
02/09/2024, 4:24 PMrp_st
02/10/2024, 9:02 AMrp_st
02/10/2024, 9:02 AMsammon2412
02/10/2024, 9:04 AMsammon2412
02/10/2024, 9:06 AMsammon2412
02/10/2024, 9:06 AMrp_st
02/10/2024, 9:06 AMrp_st
02/10/2024, 9:06 AMsammon2412
02/10/2024, 9:07 AMrp_st
02/10/2024, 9:08 AMsammon2412
02/10/2024, 9:08 AMsammon2412
02/10/2024, 9:09 AMrp_st
02/10/2024, 9:09 AMrp_st
02/10/2024, 9:09 AMrp_st
02/10/2024, 9:09 AMrp_st
02/10/2024, 9:09 AMsammon2412
02/10/2024, 9:09 AMrp_st
02/10/2024, 9:09 AMrp_st
02/10/2024, 9:09 AMsammon2412
02/10/2024, 9:10 AMsammon2412
02/10/2024, 9:11 AMsammon2412
02/10/2024, 9:12 AMjs
export const SuperTokensConfig = {
appInfo: {
appName: "croohm",
apiDomain: getApiDomain(),
websiteDomain: getWebsiteDomain(),
apiBasePath: "/auth", // Set the api_base_path here
// websiteBasePath: "/auth", // Set the website_base_path here
apiGatewayPath: "/prod", // Set the api_gateway_path here
},
// recipeList contains all the modules that you want to
// use from SuperTokens. See the full list here: https://supertokens.com/docs/guides
recipeList: [
EmailPassword.init(),
Session.init({
tokenTransferMethod: "header", // or "cookie"
}),
],
};
sammon2412
02/10/2024, 9:12 AMrp_st
02/10/2024, 9:14 AMrp_st
02/10/2024, 9:14 AMrp_st
02/10/2024, 9:14 AMsammon2412
02/10/2024, 9:19 AMsammon2412
02/10/2024, 9:21 AMsammon2412
02/10/2024, 9:22 AM