• Sun Walker

    Sun Walker

    2 years ago
    Ah so I don't need to do a generic /check route with the middleware, this call actually checks if there is an active session in the db?
  • r

    rp

    2 years ago
    i'm not sure what the /check route was for
  • Sun Walker

    Sun Walker

    2 years ago
    just so that the request passes through supertokens.middleware() so that supertokens can check if the user has correct credentials being sent
  • r

    rp

    2 years ago
    ahh i see. Yea, so you do not need that. You can just use
    await supertokens.doesSessionExist()
    which returns a boolean
  • r

    rp

    2 years ago
    true = session is alive, else false
  • Sun Walker

    Sun Walker

    2 years ago
    So I need both:
    /check
    (get request to go through supertokens.middleware) and
    await supertokens.doesSessionExist()
    both on app load
  • Sun Walker

    Sun Walker

    2 years ago
    Or just 1?
  • r

    rp

    2 years ago
    hmmm you just need await supertokens.doesSessionExist()
  • r

    rp

    2 years ago
    you should never need to call the /check API
  • Sun Walker

    Sun Walker

    2 years ago
    Ah, cool this is my function to run on initial app load (removed /check)
    JavaScript
      const initialCheck = async () => {
        const val = await st.doesSessionExist();
        const id = await getUserId();
        if (val && id) {
          setAuthFlow({ loading: false, loggedIn: true, pop: true });
        } else {
          setAuthFlow({ loading: false, loggedIn: false, pop: true });
        }
      };