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
  • a

    Amin

    06/07/2021, 9:03 AM
    Thanks a lot!
  • a

    Amin

    06/07/2021, 10:20 AM
    I use node.js for backend and my sign in api is this,when i submit login botton, i get this error: Something went wrong. Please try again
  • a

    Amin

    06/07/2021, 10:20 AM
    app.post('/api/auth/signin', function (req, res) { //const user = req.body.username; //const pwd = req.body.password; const user = req.body.formFields[0].value; const pwd = req.body.formFields[1].value; // return 400 status if username/password is not exist if (!user || !pwd) { return handleResponse(req, res, 400, null, "Username and Password required."); } const userData = userList.find(x => x.username === user && x.password === pwd); // return 401 status if the credential is not matched if (!userData) { return handleResponse(req, res, 401, null, "Username or Password is Wrong."); } // get basic user details const userObj = getCleanUser(userData); // generate access token const tokenObj = generateToken(userData); // generate refresh token const refreshToken = generateRefreshToken(userObj.userId); // refresh token list to manage the xsrf token refreshTokens[refreshToken] = tokenObj.xsrfToken; // set cookies res.cookie('refreshToken', refreshToken, COOKIE_OPTIONS); res.cookie('XSRF-TOKEN', tokenObj.xsrfToken); return handleResponse(req, res, 200, { user: userObj, token: tokenObj.token, expiredAt: tokenObj.expiredAt }); });
  • a

    Amin

    06/07/2021, 10:23 AM
    when i log userData ,everything is fine and finally my backend send response:
  • a

    Amin

    06/07/2021, 10:23 AM
    { token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxMjMiLCJuYW1lIjoiQ2x1ZSIsInVzZXJuYW1lIjoiYW1pbkBnbWFpbC5jb20iLCJpc0FkbWluIjp0cnVlLCJpYXQiOjE2MjMwNjEwNDIsImV4cCI6MTYyMzA2MTk0Mn0.Z6N8lxwxjPy2hbQKTUqlsoRRQFStFnz-ySmQH04sr7g', expiredAt: 1623061942908, xsrfToken: 'HPW9JMVfA4XYf0Zn8bayhssO' }
  • a

    Amin

    06/07/2021, 10:23 AM
    but in login page i took error => Something went wrong. Please try again
  • r

    rp

    06/07/2021, 10:56 AM
    @User , I have a related question, do you want to modify the default signin API in someway?
  • r

    rp

    06/07/2021, 10:57 AM
    If not, then you don't need to manually implement the API like you have
  • a

    Amin

    06/07/2021, 10:58 AM
    Yes,We have our backend and our database to store users informations
  • r

    rp

    06/07/2021, 10:58 AM
    Got it.
  • r

    rp

    06/07/2021, 10:59 AM
    So you should see our signin implementation, and base yours off that. Our signin impl: https://github.com/supertokens/supertokens-node/blob/master/lib/ts/recipe/emailpassword/api/signin.ts
  • a

    Amin

    06/07/2021, 11:00 AM
    thanks
  • r

    rp

    06/07/2021, 11:01 AM
    For example, you don't need to do session management yourself and can use our session recipe. In this API, you would want to call
    createNewSession
    function after you get the userId info like here: https://github.com/supertokens/supertokens-node/blob/master/lib/ts/recipe/emailpassword/api/signin.ts#L73
  • r

    rp

    06/07/2021, 11:03 AM
    And the output of this API must be of type:
    {
      status: "OK",
      user: {
        id: string,
        email: string
      }
    }
    In general, you want to follow the API spec for the APIs as mentioned here: https://github.com/supertokens/frontend-driver-interface/blob/master/v1.8.0.md
  • r

    rp

    06/07/2021, 11:03 AM
    This is the API spec for the signin API: https://github.com/supertokens/frontend-driver-interface/blob/master/v1.8.0.md#signin-api
  • r

    rp

    06/07/2021, 11:15 AM
    I've also sent you a DM. Please have a look when you get the chance
  • u

    user

    06/09/2021, 2:20 AM
    Would it be possible to use SuperTokens in a headless fashion (meaning we take control of the frontend)?
  • r

    rp

    06/09/2021, 4:29 AM
    @User yes. Your frontend can query the APIs exposed by our backend SDK. The APIs are here: https://github.com/supertokens/frontend-driver-interface/blob/master/v1.8.0.md In the above file, APIs are divided by recipe. This being said, you may still want to use our session management lib (supertokens-website, or the session recipe from supertokens-auth-react)
  • r

    Rododendronborodo

    06/09/2021, 11:43 AM
    Hello! Is it possible to somehow override default behaviour while accesing a protected page with Nextjs? I don't want to redirect the user immediately, but show some message before that.
  • r

    rp

    06/09/2021, 11:45 AM
    Yea.. You can pass the
    requireAuth
    prop to the auth wrapper component and set it to
    false
    . Like shown here: https://supertokens.io/docs/thirdpartyemailpassword/common-customizations/sessions/checking-session-front-end#with-react-context (See step 2)
  • r

    rp

    06/09/2021, 11:45 AM
    Then in your component, you can use the session context to query if a session exists or not. And show UI accordingly.
  • r

    Rododendronborodo

    06/09/2021, 12:28 PM
    Thanks for the answers! I understand what I should do now, but... I am following your guide for nextJS implementation, so i create the wrapper as such:
    const ThirdPartyEmailPasswordAuthNoSSR = dynamic(
      new Promise((res) =>
        res(ThirdPartyEmailPassword.ThirdPartyEmailPasswordAuth)
      ),
      { ssr: false }
    );
  • r

    Rododendronborodo

    06/09/2021, 12:29 PM
    And I wrap the protected page component with it. And that makes Typescript complain, about it not having the requiredAuth prop
  • r

    rp

    06/09/2021, 12:30 PM
    Yup.. So you can use it like this:
    <ThirdPartyEmailPasswordAuthNoSSR requireAuth={false}>
      <YourComponent />
    </ThirdPartyEmailPasswordAuthNoSSR>
    About the TS complaint, for now, you can do something like this (as a hack.. until we fix it):
    <ThirdPartyEmailPasswordAuthNoSSR {...{requireAuth: false} as any}}>
      <YourComponent />
    </ThirdPartyEmailPasswordAuthNoSSR>
  • r

    Rododendronborodo

    06/09/2021, 12:33 PM
    Great! It works. Thanks, you've been a great help. Take care.
  • r

    rp

    06/09/2021, 12:33 PM
    If you want, you can create an issue about the TS error on out github.
  • r

    rp

    06/09/2021, 2:32 PM
    @User , I have created an issue for this on our github: https://github.com/supertokens/docs/issues/23 Feel free to watch it so that when it's fixed, you can be notified 🙂
  • u

    user

    06/10/2021, 11:06 AM
    Just playing a bit around with SuperTokens.io. Following the documentation: https://supertokens.github.io/supertokens-node-mongo-ref-jwt/docs/backend/installation - I get error: npm i --save supertokens-node-mongo-ref-jwt@^3.3.0 npm ERR! code ETARGET npm ERR! notarget No matching version found for supertokens-node-mongo-ref-jwt@^3.3.0.
  • u

    user

    06/10/2021, 11:09 AM
    Ah, I just saw it's based on Java, after plyaing around with the getting started tutorials. That kinda kills it for me
  • u

    user

    06/10/2021, 11:09 AM
    However, looking at https://supertokens.github.io/supertokens-node-mongo-ref-jwt/docs/introduction/what-and-why it doesn't say anything about Java. I am super confused.
Powered by Linen
Title
u

user

06/10/2021, 11:09 AM
However, looking at https://supertokens.github.io/supertokens-node-mongo-ref-jwt/docs/introduction/what-and-why it doesn't say anything about Java. I am super confused.
View count: 1