hello, im getting 401 unauthorized when im trying to use the verifySession() middleware, any idea wh...
t
hello, im getting 401 unauthorized when im trying to use the verifySession() middleware, any idea what can the problem be? I'm using EmailPassword recipe. Also I have another question, can I use the SessionRequest object in a js object not ts ? im trying to get the token payload
r
Hey @tajin_malsou9a
Can you enable debug logging and show me the output when you call the API that returns 401?
Also, you can use SuperTokens with JS as well.
t
I tried to enable it , but I didn't know where to type this command "SET DEBUG=com.supertokens"
r
terminal
t
Can you tell me where to execute it?
r
run it before you run the node command
t
im using git bash , and i get this error" bash: SET: command not found"
i'll use cmd
r
then just run
DEBUG=com.supertokens node ...
t
i just ran this
DEBUG=com.supertokens nodemon server.js
and it didn't work
r
what do you mean by didn't work?
t
not getting any logs
r
which version of the node SDK?
t
at all , the same messages are showing
9.0.1
oh
it shouldn't work nvm
i need to update to something after this v9.1.2
r
yup.
so please do, and then show me the logs
t
alright will do
this is what i got
r
so the cookies are not being sent.
Can you enable debug logs on the frontend as well and show me the output when you make the API call?
t
okay will do
r
which SDK are you using on ther frontned?
i'll tell u the min version you need to enable logs in there - since it's not mentioned in the docs
t
"supertokens-auth-react": "^0.19.0",
r
you wanna upgrade to version 0.21.1
it may break a few things depending on what features you are using, but you can always revert back after fixing this issue
t
i added the enable debug in init function but im not seeing any changes in the browser's console
wait
sorry
r
you need to use SDK versnion 0.21.1 on the frontend
t
i thought i updated it , didn't work
okay so , when i first login i get those logs, but when i do make the api call i don't see any logs
yyou want me to show you the logs upon login?
r
right yea. SO are you making the API calls using axios?
t
react query
axios yes
r
you need to add the supertokens interceptors to the axios instance
t
okay im on it
okay ,apprently it worked thank you!
r
great
t
can you help me in just 1 more thing tho?
r
sure
t
im trying to use this" req: SessionRequest" in a js file but im geting the "type annotatiosn can only be used in typescript files"
r
yea.. u cant use typescript types in a JS file
t
oh i think my second problem would be solved after fixing that first problem ( second one is access that req.session object)
and retrieving the payload
r
yup. that should work now
t
the thing is, im doing `console.log(req.session)`but it says its undefined
r
is the verifySession function succeeding? can i see the code?
t
this is the endpoint
Copy code
router.get("/get_course", verifySession(), (req, res) => {
  console.log("hi");
  // const { user_who_requested_id } = req.query;

  console.log(req.sesion);
  let courseId = req.query.courseId;

  courseServices
    .getCourse({ id: courseId })
    .then((course) => {
      res.status(200).json(course);
    })
    .catch((error) => {
      console.log(error);
      res.status(400).json({
        message: "There was a problem retrieving the courses.",
      });
    });
});
this endpoint used to give me 401 unauthorized, but after fixing that it succeeds in returning the reponse i want
so we can conclude that verifySession works now?
r
you have a typo
t
i see it now
r
you are printing out req.sesion
t
wow
r
😅
t
woah
well , i have nothing to say than thanks again lol and sorry for wasting your time
r
happy to help 🙂
t
what im trying to implement is , i will be reading the role of the one who sent that request, if it's the one authorized to request that ressource i'll return the ressource else i will return an error, it should be done there right?
just asking for ur opinion
r
yea. makes sense.
70 Views