https://supertokens.com/ logo
t

Tajin

05/14/2022, 4:50 PM
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

rp

05/14/2022, 4:52 PM
Hey @Tajin
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

Tajin

05/14/2022, 4:53 PM
I tried to enable it , but I didn't know where to type this command "SET DEBUG=com.supertokens"
r

rp

05/14/2022, 4:53 PM
terminal
t

Tajin

05/14/2022, 4:53 PM
Can you tell me where to execute it?
r

rp

05/14/2022, 4:53 PM
run it before you run the node command
t

Tajin

05/14/2022, 4:54 PM
im using git bash , and i get this error" bash: SET: command not found"
i'll use cmd
r

rp

05/14/2022, 4:54 PM
then just run
DEBUG=com.supertokens node ...
t

Tajin

05/14/2022, 4:58 PM
i just ran this
DEBUG=com.supertokens nodemon server.js
and it didn't work
r

rp

05/14/2022, 4:59 PM
what do you mean by didn't work?
t

Tajin

05/14/2022, 4:59 PM
not getting any logs
r

rp

05/14/2022, 4:59 PM
which version of the node SDK?
t

Tajin

05/14/2022, 4:59 PM
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

rp

05/14/2022, 5:00 PM
yup.
so please do, and then show me the logs
t

Tajin

05/14/2022, 5:00 PM
alright will do
this is what i got
r

rp

05/14/2022, 5:08 PM
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

Tajin

05/14/2022, 5:09 PM
okay will do
r

rp

05/14/2022, 5:09 PM
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

Tajin

05/14/2022, 5:10 PM
"supertokens-auth-react": "^0.19.0",
r

rp

05/14/2022, 5:11 PM
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

Tajin

05/14/2022, 5:13 PM
i added the enable debug in init function but im not seeing any changes in the browser's console
wait
sorry
r

rp

05/14/2022, 5:14 PM
you need to use SDK versnion 0.21.1 on the frontend
t

Tajin

05/14/2022, 5:14 PM
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

rp

05/14/2022, 5:18 PM
right yea. SO are you making the API calls using axios?
t

Tajin

05/14/2022, 5:18 PM
react query
axios yes
r

rp

05/14/2022, 5:18 PM
you need to add the supertokens interceptors to the axios instance
t

Tajin

05/14/2022, 5:19 PM
okay im on it
okay ,apprently it worked thank you!
r

rp

05/14/2022, 5:21 PM
great
t

Tajin

05/14/2022, 5:23 PM
can you help me in just 1 more thing tho?
r

rp

05/14/2022, 5:23 PM
sure
t

Tajin

05/14/2022, 5:24 PM
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

rp

05/14/2022, 5:24 PM
yea.. u cant use typescript types in a JS file
t

Tajin

05/14/2022, 5:25 PM
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

rp

05/14/2022, 5:25 PM
yup. that should work now
t

Tajin

05/14/2022, 5:27 PM
the thing is, im doing `console.log(req.session)`but it says its undefined
r

rp

05/14/2022, 5:27 PM
is the verifySession function succeeding? can i see the code?
t

Tajin

05/14/2022, 5:28 PM
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

rp

05/14/2022, 5:29 PM
you have a typo
t

Tajin

05/14/2022, 5:29 PM
i see it now
r

rp

05/14/2022, 5:29 PM
you are printing out req.sesion
t

Tajin

05/14/2022, 5:29 PM
wow
r

rp

05/14/2022, 5:29 PM
😅
t

Tajin

05/14/2022, 5:29 PM
woah
well , i have nothing to say than thanks again lol and sorry for wasting your time
r

rp

05/14/2022, 5:30 PM
happy to help 🙂
t

Tajin

05/14/2022, 5:31 PM
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

rp

05/14/2022, 5:34 PM
yea. makes sense.
2 Views