I'm having some trouble routing the user from the ...
# support-questions-legacy
b
I'm having some trouble routing the user from the signup form to the
passwordless
phone number input after sign up. I'm overriding emailpassword's
signUpPOST
function by calling: -
signUp
(/recipe/emailpassword) -
createNewSession
(/recipe/session)
Copy code
signUpPOST: async function (input) {
    let signup = await signUp(
        email,
        password,
        input.userContext
    );

    if (signup.status === 'OK') {
        // Create database user
        ...

        // Create session
        return createNewSession(
            input.options.res,
            signup.user.id,
            undefined,
            undefined,
            input.userContext
        );
    }
}
I'm unsure if the
input
variables I'm passing here are correct, or if there is another recipe function I should be calling. The session and user seem to be created properly, but the frontend requires a manual refresh in order to reach the
passwordless
Second factor auth (phone number input page). Without a manual refresh, the frontend says to sign in instead since the email is already in use.
r
Hey @Bailey
What’s the response from the sign up API call?
b
Copy code
{
  status: 'OK',
  user: {
    email: 'b.....@hotmail.ca',
    id: 'fb7aaa17-50aa-4074-8297-5de0947ad2f8',     
    timeJoined: 1669300965495
  }
}
createNewSession return value:
Copy code
{
  originalSessionClass: Session {
    sessionHandle: '7def5259-9c0c-49c4-aee0-d6b90bd44aa2',
    userId: 'fb7aaa17-50aa-4074-8297-5de0947ad2f8', 
    userDataInAccessToken: {
      'st-ev': {
        v: false,
        t: 1669301109625
      },
      '2fa-completed': {
        v: false,
        t: 1669301109753
      },
      username: 'test5',
      verified: false,
      role: 'User',
      jwt: '...',
      _jwtPName: 'jwt'
    },
    res: ExpressResponse {
      wrapperUsed: true,
      sendHTMLResponse: [Function (anonymous)],     
      setHeader: [Function (anonymous)],
      setCookie: [Function (anonymous)],
      setStatusCode: [Function (anonymous)],        
      sendJSONResponse: [Function (anonymous)],     
      original: [ServerResponse],
      response: [ServerResponse],
      statusCode: 200
    },
    accessToken: '...',      
    helpers: {
      querier: [Querier],
      updateJwtSigningPublicKeyInfo: [Function: updateJwtSigningPublicKeyInfo],
      getHandshakeInfo: [Function: getHandshakeInfo],
      config: [Object],
      getRecipeImpl: [Function (anonymous)]
    }
  },
  openIdRecipeImplementation: {
    getOpenIdDiscoveryConfiguration: [Function: bound getOpenIdDiscoveryConfiguration],
    createJWT: [Function: bound createJWT],
    getJWKS: [Function: bound getJWKS],
    _call: [Function: bound _call]
  }
}
Are
recipe/emailpassword/signUp()
and
recipe/session/createNewSession()
the only functions I should need to call to replicate the signUpPost override?
r
Yes. Correct t
Hmm. The response seems fine
So when this response is returned, what exactly happens?
I think the issue might be on the frontend customisations done by you. Did you follow the MFA example / guide we have on the frontend?
b
I followed the tutorial, and referenced this github example (https://github.com/supertokens/supertokens-auth-react/tree/master/examples/with-thirdpartyemailpassword-2fa-passwordless) After pressing Sign Up, the frontend updates to indicate that the email is already taken (see screenshot, email is in use by the newly created account). Refreshing the page brings me to
/verify-email
, and after that is completed the frontend goes to the 2fa passwordless process. When I use the standard
oI.signUpPOST(input)
the frontend acts normally, redirecting me to
/verify-email
automatically.
Updated the github example link
I updated the github example with the following change, and it encountered the same problem I'm having:
Copy code
const { signUp } = require('supertokens-node/recipe/emailpassword');
const { createNewSession } = require('supertokens-node/recipe/session');
...
EmailPassword.init({
    override: {
        apis: (oI) => {
            return {
                ...oI,
                signUpPOST: async function (input) {
                    // Supertokens signup
                    let signup = await signUp(
                        input.formFields[0].value,
                        input.formFields[1].value,
                        input.userContext
                    );

                    // Create database user
                    if (signup.status === 'OK') {
                        // Create session
                        return await createNewSession(
                            input.options.res,
                            signup.user.id,
                            undefined,
                            undefined,
                            input.userContext
                        );
                    }

                    return {
                        status: 'GENERAL_ERROR',
                        message: 'Something went wrong'
                    }
                },
            };
        },
    }
}),
I found the solution in the sourcecode for the
signUpPOST
function.
signUpPOST
is supposed to return an object like this and not just the session:
Copy code
return {
    status: "OK",
    session, // createNewSession()
    user: signup.user // signUp().user
};
r
Ah right! Okay
17 Views