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

    ankitjey

    04/24/2021, 12:39 PM
    return send200Response(res, {
          status: 'FIELD_ERROR',
          formFields: {
            id: 'email',
            error:
              'This email is already in use via a social provider. Please sign in instead.',
          },
        });
    this doesn't seem to work, not showing any error on the ui
  • r

    rp

    04/24/2021, 1:09 PM
    > Another thing, in the methods all the errors are thrown which I think would be catched by the supertokens error handler, how can I achieve that You would need to generate an error using the supertokens error functions. You can see an example of this here: - https://github.com/supertokens/supertokens-node/blob/master/lib/ts/recipe/emailpassword/coreAPICalls.ts#L55 - There is also
    GENERAL_ERROR
    (example here: https://github.com/supertokens/supertokens-node/blob/master/lib/ts/recipe/emailpassword/api/signin.ts#L63), which if thrown passes the
    err
    object to your error handler.
  • r

    rp

    04/24/2021, 1:13 PM
    @User
    formFields
    must be an array:
    return send200Response(res, {
        status: 'FIELD_ERROR',
        formFields: [{
            id: 'email',
            error:
              'This email is already in use via a social provider. Please sign in instead.',
        }],
    });
  • a

    ankitjey

    04/24/2021, 1:23 PM
    > which if thrown passes the err object to your error handler What should the error handler send in response, that's what I was asking
  • a

    ankitjey

    04/24/2021, 1:24 PM
    when it receives the err object
  • r

    rp

    04/24/2021, 1:25 PM
    > What should the error handler send in response, that's what I was asking Your error handler? It can send a 500 response.. whatever you want.. Other APIs you make will also use this same error handler im guessing. So a generic something went wrong error I guess.
  • a

    ankitjey

    04/24/2021, 1:29 PM
    What about errors like these
    throw new STError(
          {
            type: STError.BAD_INPUT_ERROR,
            message: 'Please provide the code in request body',
          },
          recipeInstance,
        );
    Shouldn't they be received by the UI or something?
  • r

    rp

    04/24/2021, 1:30 PM
    Those would go to your error handler too. You can send them to the frontend and display an appropriate error. But showing something like "Please provide the code in request body" to your end user wouldn't make sense anyway
  • a

    ankitjey

    04/24/2021, 2:01 PM
    Thanks a lot @User , everything works now
  • r

    rp

    04/24/2021, 2:02 PM
    great!! We will definitely work on making customisations to APIs easier
  • a

    ankitjey

    04/24/2021, 2:02 PM
    > You can create an issue about displaying a specific message (that can be read from the 400 error respose) and we can implement it very soon. Which repo should I create this issue in?
  • r

    rp

    04/24/2021, 2:02 PM
    https://github.com/supertokens/supertokens-core/issues
  • r

    rp

    04/24/2021, 5:00 PM
    @User I have released a new version of our SDKs to give you the feature you requested: - supertokens-auth-react: v0.9.1 - supertokens-node: v4.3.2 You can safely upgrade to the above without any breaking changes. To send a custom error message that displays on the frontend, you can throw the following error from your signinup API:
    throw new STError(
            {
                type: "FIELD_ERROR",
                message: "Some custom message"
            },
            recipeInstance
        );
    This will show "Some custom message" on the signup screen when the user tries to login using a social provider.
  • a

    ankitjey

    04/24/2021, 7:39 PM
    Cool, I'll try it tomorrow, thanks
  • x

    xonar7

    04/25/2021, 7:48 AM
    Hi! Could somebody please elaborate why do we need idRefreshToken?
  • r

    rp

    04/25/2021, 8:03 AM
    The purpose of that is to: - Let the frontend know about changes in refresh token without actually having access to the refresh token. This is used to synchornise parallel calls to the refresh API. - Let the backend know that a session exists even if the access token has expired, and without sending the actual refresh token to all APIs.
  • r

    rp

    04/25/2021, 8:04 AM
    So the lifetime of
    idRefreshToken
    is the same as that of the refresh token, and whenever the refresh token changes, so does the value of
    idRefreshToken
    . However, the value of
    idRefreshToken
    itself is meaningless.
  • x

    xonar7

    04/25/2021, 9:58 AM
    @User Thank you for quick reply! I've looked through the code of nodejs-sdk and supertokens-core, and still can't say usage of idRefreshToken became clear to me (the purpose of idRefreshTokenHeader is unclear too). But I'll look closer to the client sdks as well, and maybe I will ask more specific questions. If there are any sequence diagrams with usage of idSessionToken (cookie and header) in documentation it will be very helpfull. Thanks.
  • r

    rp

    04/25/2021, 9:59 AM
    There isn't any diagram as such yet 😦 But we can add it soon.
  • r

    rp

    04/25/2021, 9:59 AM
    The purpose of
    idRefreshToken
    is exactly what I described in my previous comment.
  • u

    user

    04/25/2021, 10:17 AM
    hey @User! so, I have the following config for the frontend SDK:
    appInfo: {
        appName: "WorkoutApp",
        apiDomain: "https://blah-blah.execute-api.blah-blah.amazonaws.com",
        apiBasePath: "/dev/auth",
        websiteDomain: "https://blah-blah.execute-api.blah-blah.amazonaws.com/dev/auth",
      },
    but then on SignUp I get a CORS-related error:
    Access to fetch at 'https://blah-blah.execute-api.blah-blah.amazonaws.com/dev/auth/signup/email/exists?email=qwwqwq%40hahah.com' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
    I think earlier you mentioned that
    apiDomain
    and
    websiteDomain
    have to be the same 🤔
  • r

    rp

    04/25/2021, 10:33 AM
    So the
    websiteDomain
    should be
    "https://blah-blah.execute-api.blah-blah.amazonaws.com"
    and there is
    websiteBasePath
    which should be changed to
    "/dev/auth"
    . For development, youe
    websiteDomain
    will be
    "http://localhost:3000"
    . Finally, CORS error can be fixed by doing this step: https://supertokens.io/docs/thirdpartyemailpassword/quick-setup/backend#3-add-the-supertokens-and-cors-middleware, where the
    origin
    value should be
    "http://localhost:3000"
    .
  • r

    rp

    04/25/2021, 10:34 AM
    CORS is not required when the api domain is the same as the website domain (as is usually the case in a nextjs app). But in your case, the api domain is
    https://blah-blah.execute-api.blah-blah.amazonaws.com
    , and the website domain (during dev) is
    http://localhost:3000
    . So you need to deal with CORS.
  • u

    user

    04/25/2021, 3:05 PM
    okay, did all that and now the SignUp/In form doesn't show... 😄 😄
  • r

    rp

    04/25/2021, 3:06 PM
    You need to navigate to
    http://localhost:3000/dev/auth
    for the form
  • r

    rp

    04/25/2021, 3:06 PM
    since you have set the
    websiteBasePath
    to
    /dev/auth
  • r

    rp

    04/25/2021, 3:07 PM
    If you want the form to show up in
    /auth
    , then you can remove the use of
    websiteBasePath
    from the frontend and backend config.
  • u

    user

    04/25/2021, 3:09 PM
    yes, that worked out. but wait. why the URL path in my frontend should be dependent on some config? what if I have this:
    <Route exact path="/authed">
    ?
  • r

    rp

    04/25/2021, 3:09 PM
    > what if I have this: ? What do you mean?
  • u

    user

    04/25/2021, 3:10 PM
    look:
Powered by Linen
Title
u

user

04/25/2021, 3:10 PM
look:
View count: 1