tylerdane
07/27/2022, 1:58 PMtylerdane
07/27/2022, 1:58 PMverifySession()
middleware, I get a 401 and these debug messages:
Not handling because no recipe matched
...
requestRID is: undefined
...
UNAUTHORISED because idRefreshToken from cookies is undefined
...
Session does not exist. Are you sending the session tokens in the request as cookies?
My understanding was that the axios interceptors would handle storing & including cookies in subsequent requests. But I still see those errors after adding the addAxiosInterceptors
middleware (via both axios.create()
and manually in each axios import
Any idea what I'm doing wrong?
----
More info:
- I went through the Supertokesn Postman tutorial without issues. Since Postman handles the cookie stuff, it makes me think that I might need to do something on my end to ensure supertokens cookies are always sent in requests, in addition to adding the axios interceptors(?)
----
Stack: Node, React, Axios, SuperTokens Managed Hostingjscyo
07/27/2022, 2:03 PMjscyo
07/27/2022, 2:05 PMtylerdane
07/27/2022, 2:05 PMimport axios from "axios";
import Session from "supertokens-auth-react/recipe/session";
Session.addAxiosInterceptors(axios);
... my api calls
import axios from "axios";
import Session from "supertokens-auth-react/recipe/session";
export const MyApi = axios.create({
baseURL: http://localhost:3000/api,
});
Session.addAxiosInterceptors(MyApi);
... my api calls
tylerdane
07/27/2022, 2:18 PM//my.api.ts
import axios from "axios";
Session.addAxiosInterceptors(axios);
export const createSession = async () => {
const response = await axios.post(`http://localhost:3000/api/session`);
};
export const verifySession = async () => {
const response = await axios.post(`http://localhost:3000/api/verify-demo`);
};
----
//MyComponent.tsx
import {createSession, verifySession} from "./my.api"
return (
<button onClick={async () => await createSession()}>Create Session</button>
<button onClick={async () => await verifySession()}>Verify Session</button>
)
----
// my.backend.ts
// this works
app.post("/api/session", async (req, res) => {
const uid = Math.floor(Math.random() * 100);
const user = `test-user-${uid}`;
await Session.createNewSession(res, user, {}, {});
res.send({
message: `user session created: ${user}`,
});
});
// this fails
app.post(
"/api/verify-demo",
verifySession(),
async (req: SessionRequest, res) => {
const userId = req.session!.getUserId();
res.send({
userId,
});
}
);
tylerdane
07/27/2022, 2:33 PMapiDomain
port (by using the frontend port, not backend port)
For reference, here's what I mean:
//app.ts
SuperTokens.init({
enableDebugLogs: true,
appInfo: {
appName: "My App",
apiDomain: "http://localhost:<backendPort>", // <-- I was trying to use frontend port fhere
websiteDomain: "http://localhost:<frontendPort>",
apiBasePath: "/api",
websiteBasePath: "/super",
},
recipeList: [Session.init()],
});
We're all good nowrp_st
07/27/2022, 2:33 PMSuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by