https://supertokens.com/ logo
Docs
Join the conversationJoin Discord
Channels
community
contributing
general
github-activity
info
introductions
new-releases
random
security
support-questions
welcome-0xdelusion
welcome-aj-ya
welcome-aleksandrc
welcome-alpinjs
welcome-amberlamps1
welcome-andrew-rodriguez
welcome-ankit-choudhary
welcome-anthony-stod-custodio
welcome-call-in
welcome-chwalbox
welcome-claybiokiller
welcome-co7e
welcome-cosmoecwsa
welcome-devdag
welcome-dinso
welcome-drebotelho
welcome-elio
welcome-ernest
welcome-foxbarrington
welcome-fromscratch
welcome-galto4ir
welcome-goetzum
welcome-hay-kot
welcome-himanshu-kukreja
welcome-hossambarakat
welcome-ichikawakazuto
welcome-jahir9991
welcome-jamesl
welcome-jerry123424
welcome-john-oliver
welcome-jonas-alexanderson
welcome-jxyz
welcome-kelvinwop
welcome-kraz
welcome-lancekey
welcome-leoo
welcome-lukeacollins
welcome-m-j-mon
welcome-malik-khoja
welcome-marco
welcome-mardadi
welcome-meshguy
welcome-metamorph
welcome-mike-tectu
welcome-mirzok
welcome-mozomig
welcome-naberyou66_
welcome-nacer
welcome-namratha
welcome-naveenkumar
welcome-nightlight
welcome-nischith
welcome-notankit
welcome-olawumi
welcome-pavan-kumar-reddy-n
welcome-pineappaul
welcome-poothebear
welcome-rick
welcome-samuel-qosenergy
welcome-samuelstroschein
welcome-shubhamgoel23
welcome-shubhamkaushal
welcome-sidebar
welcome-surajsli
welcome-suyash_
welcome-syntaxerror
welcome-tauno
welcome-tauno
welcome-tawnoz
welcome-teclali
welcome-tls
welcome-turbosepp
welcome-vikram_shadow
welcome-yann
Powered by Linen
general
  • s

    Sun Walker

    03/25/2020, 3:10 PM
    Hey SuperTokens, I currently have this middleware that runs on every request
    export const secureRoute = async (req: any, _res: any, next: any) => {
      const { authorization } = req.headers;
    
      if (!authorization) {
        throw new Unauthorized();
      }
      try {
        const token = authorization.replace('Bearer ', '');
        const payload: any = await verifyAccessToken(token);
        if (!payload) {
          throw new Unauthorized();
        }
    
        req.currentUserId = payload.sub;
    
        return next();
      } catch (err) {
        throw createHttpError(401, { err });
      }
    };
    Is there any way to put supertoken session in this or do I not need this any more?
  • r

    rp

    03/25/2020, 3:13 PM
    you will need a new middleware. An example of that is given here: https://supertokens.io/docs/nodejs/usage-with-express/verify-session#writing-your-own-session-middleware (if you are using express)
  • s

    Sun Walker

    03/25/2020, 6:40 PM
    What does one usually store in session data? (as jwtPayload is stored on the session)
  • r

    rp

    03/25/2020, 6:41 PM
    So jwtPayload is sent to the frontend. Usually u store the userId and then user role in there. (UserId is already stored there for u). But u should not store anything sensitive
  • r

    rp

    03/25/2020, 6:41 PM
    Anything sensitive goes in sessionData. Which is only stored in db.
  • s

    Sun Walker

    03/25/2020, 6:42 PM
    do you have examples of such sensitive data?
  • s

    Sun Walker

    03/25/2020, 6:42 PM
    just 1 or so
  • r

    rp

    03/25/2020, 6:42 PM
    Uhmm not reallly. But it could be whatever u think is sensitive. Like an email ID. Or phone number or shopping cart information etc..
  • r

    rp

    03/25/2020, 6:43 PM
    Generally I would avoid storing much in JWT payload. Just the minimum stuff. Or stuff that’s required for all API calls (like userId or user role)
  • s

    Sun Walker

    03/25/2020, 6:45 PM
    Ahhh I see
  • r

    rp

    03/25/2020, 6:45 PM
    But this is debatable. Cause the JWT is not meant to be accessible on the frontend anyway.. but this is what I am conmfortable with
  • s

    Sun Walker

    03/25/2020, 6:47 PM
    Yeah I too agree, it's a good balance between risk and making things easier for FE
  • r

    rp

    03/25/2020, 6:59 PM
    FE?
  • s

    Sun Walker

    03/25/2020, 6:59 PM
    front end
  • r

    rp

    03/25/2020, 6:59 PM
    Hmmm. How frontend?
  • r

    rp

    03/25/2020, 6:59 PM
    Cause the frontend can’t access this token anyways
  • s

    Sun Walker

    03/25/2020, 7:35 PM
    oh but dont you need to access the JWT payload or userid on the front end to show certain data and do certain things
  • r

    rp

    03/25/2020, 7:35 PM
    Ah. For that, there is this thing called open ID connect tokens. Which we have not implemented yet
  • r

    rp

    03/25/2020, 7:36 PM
    For now, u can just call an API that will send u info about the user to ur frontend
  • r

    rp

    03/25/2020, 7:36 PM
    But this JWT should never be accessible from the frontend. Cause it can be stolen via XSS attacks.
  • r

    rp

    03/25/2020, 7:36 PM
    And SuperTokens enforces this.
  • s

    Sun Walker

    03/25/2020, 7:37 PM
    Oh so cookie stored in FE, every request to api sends access token right? doesnt access token have userID?
  • r

    rp

    03/25/2020, 7:37 PM
    Yes.
  • r

    rp

    03/25/2020, 7:38 PM
    To both ur questions
  • s

    Sun Walker

    03/25/2020, 7:39 PM
    when you say 'api that will send info about user', what info does the Front End need other than user ID or if I need the user info I can just make a request to /user/:userId? Want to know to understand the different parts of this flow
  • r

    rp

    03/25/2020, 7:42 PM
    So u don’t even need an API like /user/:userId (unless u want users to see other user’s info based on their userId).
  • r

    rp

    03/25/2020, 7:42 PM
    All u need is a /user GET api which will take the incoming access token, get the userId from it, and return that user’s name profile pic etc...
  • r

    rp

    03/25/2020, 7:43 PM
    And u can call that API to get the current user’s info.
  • r

    rp

    03/25/2020, 7:43 PM
    So unless u r displaying the current user’s userId to them, ur frontend doesn’t even need the userId
  • s

    Sun Walker

    03/25/2020, 7:43 PM
    ahhh got you, yeah I need users/userId because there'll be a component of finding others
Powered by Linen
Title
s

Sun Walker

03/25/2020, 7:43 PM
ahhh got you, yeah I need users/userId because there'll be a component of finding others
View count: 2