Hi. I have implemented custom UI but standard flow...
# support-questions-legacy
a
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
Hi @agneado3085
Can I see the code for where you call SuperTokens.init?
a
frontend confi: export const frontendConfig = () => ({ appInfo, recipeList: [ EmailVerification.init({ mode: 'REQUIRED' }), EmailPassword.init({ signInAndUpFeature: { disableDefaultUI: true }, resetPasswordUsingTokenFeature: { disableDefaultUI: true } }), SessionReact.init() ] })
n
And on the backend?
a
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
Where are you importing
submitNewPassword
from?
a
import { submitNewPassword } from 'supertokens-web-js/recipe/emailpassword'
n
Just to clarify, is this a react app?
a
yes, react nextjs
n
Right you should import from the react SDK instead
Copy code
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
ahhh, ok. yeah, the docs could be simpler and with more examples for sure 🙂
thanks will check if this works now
n
Yep and thanks for pointing that out, if you have any more feedback as you go along please let us know
a
import EmailPassword from 'supertokens-auth-react/recipe/emailpassword' is this the right import
?
n
Yep thats correct
a
hey, something has changed for better, but still not working quite right
n
Oh what issue are you facing?
a
n
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
yea, i know, and i call it after i enter new password to a form
n
Whats the URL of the page?
this is the url i get as password reset link
n
Does this happen every time? Or was this a URL from an older email
a
it's the last one
n
Can you restart the flow by triggering a new email? See if you still get the error
a
no, i get the same error each time i try to reset passwrod
n
Ah
Can I see the request body for the request?
a
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
Copy code
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
ohh, but the first time i call it in console.log() is that a problem?
n
Yep itll still call the API and consume the token
So the second one will always fail
a
ok, now i feel silly 😄 thanks! It works
n
Chalk it up to it being a Friday :p
Happy to help
a
😆 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
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
14 Views