https://supertokens.com/ logo
Title
a

Agne Ado

11/18/2022, 8:56 AM
Hi. I have implemented custom UI but standard flow password reset solution. Everything seems to be working except for the last part, where I call function submitNewPassword({ formFields: [ { id: 'password', value: newPassword } ] }). it gives me this error "Error: No instance of EmailPassword found. Make sure to call the EmailPassword.init method." Can enyone help me with this issue?
n

nkshah2

11/18/2022, 8:56 AM
Hi @Agne Ado
Can I see the code for where you call SuperTokens.init?
a

Agne Ado

11/18/2022, 8:57 AM
frontend confi: export const frontendConfig = () => ({ appInfo, recipeList: [ EmailVerification.init({ mode: 'REQUIRED' }), EmailPassword.init({ signInAndUpFeature: { disableDefaultUI: true }, resetPasswordUsingTokenFeature: { disableDefaultUI: true } }), SessionReact.init() ] })
n

nkshah2

11/18/2022, 9:00 AM
And on the backend?
a

Agne Ado

11/18/2022, 9:00 AM
export const backendConfig = (): TypeInput => { return { framework: 'express', supertokens: { connectionURI: process.env.SUPERTOKENS_CONNECTION_URI || '-' }, appInfo, recipeList: [ EmailVerification.init({ mode: 'REQUIRED' }), EmailPasswordNode.init(), SessionNode.init() ], isInServerlessEnv: true } }
n

nkshah2

11/18/2022, 9:01 AM
Where are you importing
submitNewPassword
from?
a

Agne Ado

11/18/2022, 9:01 AM
import { submitNewPassword } from 'supertokens-web-js/recipe/emailpassword'
n

nkshah2

11/18/2022, 9:01 AM
Just to clarify, is this a react app?
a

Agne Ado

11/18/2022, 9:02 AM
yes, react nextjs
n

nkshah2

11/18/2022, 9:03 AM
Right you should import from the react SDK instead
import { submitNewPassword } from 'supertokens-auth-react/recipe/emailpassword'
Also make sure to import EmailPassword from the react SDK for this bit
EmailPassword.init
I know this isnt super clear in the docs at the moment but we are working on that
a

Agne Ado

11/18/2022, 9:04 AM
ahhh, ok. yeah, the docs could be simpler and with more examples for sure 🙂
thanks will check if this works now
n

nkshah2

11/18/2022, 9:05 AM
Yep and thanks for pointing that out, if you have any more feedback as you go along please let us know
a

Agne Ado

11/18/2022, 9:06 AM
import EmailPassword from 'supertokens-auth-react/recipe/emailpassword' is this the right import
?
n

nkshah2

11/18/2022, 9:06 AM
Yep thats correct
a

Agne Ado

11/18/2022, 9:26 AM
hey, something has changed for better, but still not working quite right
n

nkshah2

11/18/2022, 9:26 AM
Oh what issue are you facing?
a

Agne Ado

11/18/2022, 9:27 AM
n

nkshah2

11/18/2022, 9:29 AM
Right so the submit new password method is meant to be used on the screen where the user is navigated to after they click the reset password link in the email
It reads the token from the URL
a

Agne Ado

11/18/2022, 9:29 AM
yea, i know, and i call it after i enter new password to a form
n

nkshah2

11/18/2022, 9:30 AM
Whats the URL of the page?
this is the url i get as password reset link
n

nkshah2

11/18/2022, 9:31 AM
Does this happen every time? Or was this a URL from an older email
a

Agne Ado

11/18/2022, 9:31 AM
it's the last one
n

nkshah2

11/18/2022, 9:31 AM
Can you restart the flow by triggering a new email? See if you still get the error
a

Agne Ado

11/18/2022, 9:31 AM
no, i get the same error each time i try to reset passwrod
n

nkshah2

11/18/2022, 9:31 AM
Ah
Can I see the request body for the request?
a

Agne Ado

11/18/2022, 9:33 AM
so this is my send email request import { sendPasswordResetEmail } from 'supertokens-auth-react/recipe/emailpassword' export const sendEmail = async (email: string) => { try { const response = await sendPasswordResetEmail({ formFields: [ { id: 'email', value: email } ] }) if (response.status === 'FIELD_ERROR') { // one of the input formFields failed validaiton response.formFields.forEach(formField => { if (formField.id === 'email') { // Email validation failed (for example incorrect email syntax). console.error(formField.error) } }) } else { // reset password email sent. console.log('reset password email sent') } } catch (err: any) { if (err.isSuperTokensGeneralError === true) { // this may be a custom error message sent from the API by you. console.error(err.message) } else { console.error('Oops! Something went wrong.') } } }
and this is changePassword
import { submitNewPassword } from 'supertokens-auth-react/recipe/emailpassword' export const changePassword = async (newPassword: string) => { try { console.log('i am trying..') console.log( await submitNewPassword({ formFields: [ { id: 'password', value: newPassword } ] }) ) const response = await submitNewPassword({ formFields: [ { id: 'password', value: newPassword } ] }) if (response.status === 'FIELD_ERROR') { response.formFields.forEach(formField => { if (formField.id === 'password') { // New password did not meet password criteria on the backend. console.error(formField.error) } }) } else if (response.status === 'RESET_PASSWORD_INVALID_TOKEN_ERROR') { // the password reset token in the URL is invalid, expired, or already consumed console.error('Password reset failed. Please try again') console.error(response.status) // window.location.assign('/auth/reset-password') // back to the password reset screen. } else { console.log('Password reset successful!') window.location.assign('/signIn') } } catch (err: any) { if (err.isSuperTokensGeneralError === true) { // this may be a custom error message sent from the API by you. console.error(err.message) } else { console.log(err) console.error('Oops! Something went wrong.') } } }
n

nkshah2

11/18/2022, 9:34 AM
await submitNewPassword({
        formFields: [
          {
            id: 'password',
            value: newPassword
          }
        ]
      })
    )
    const response = await submitNewPassword({
      formFields: [
        {
          id: 'password',
          value: newPassword
        }
      ]
    })
I think you meant to call it once?
its probably consuming the token the first time and failing it the second time because the token is already used
a

Agne Ado

11/18/2022, 9:36 AM
ohh, but the first time i call it in console.log() is that a problem?
n

nkshah2

11/18/2022, 9:36 AM
Yep itll still call the API and consume the token
So the second one will always fail
a

Agne Ado

11/18/2022, 9:39 AM
ok, now i feel silly 😄 thanks! It works
n

nkshah2

11/18/2022, 9:40 AM
Chalk it up to it being a Friday :p
Happy to help
a

Agne Ado

11/18/2022, 9:42 AM
😆 thanks!
Hi, me again. I wonder, why any error is not thrown, when i try o reset password with email, that is not signedUp before. Do i have to implement something additionally? I was kind'a expecting superToken to check if this email exist in DB..
n

nkshah2

11/25/2022, 1:07 AM
Well the idea is that a non user should not be able to tell what email exists in the system by using the reset password form, but you can use the override feature to customise this
This lets you customise the behaviour of some of the functionality in SuperTokens. In essence you want to override the reset password function and return a general error if the email does not exist in the system