Hello ! I am looking for a solution to have a cust...
# support-questions
r
Hello ! I am looking for a solution to have a custom password validation according to a client. My first idea is to add a password formfield validate method (https://supertokens.com/docs/thirdpartyemailpassword/common-customizations/signup-form/field-validators#step-2-back-end-) But to do this i need to call an API inside the validate method with a clientId (so the front need to send this ID to the validate method), is there a way to do this? Thanks in advance for your help πŸ™‚
n
Hi @Romain , If you are using the
supertokens-auth-react
on the frontend you could add your custom validator on the frontend itself
r
Unfortunately it will be the supertoken javascript (we are in VueJs)
And having the validation only on the front end doesn't cover us from a user who would signup with a direct API call 😒
n
Right, one way to do that is to return
undefined
in the validator (the one you linked to) for password. This will disable the SDKs validation for it You can then use our override feature to override the sign in/sign up functions and perform your validation there
r
Okay I will try this thanks πŸ™‚ And I can pass the clientId from the front in an override method ?
n
For the backend, the input to the function will include details from the request. You should be able to access the client id from there. For the frontend since you are using the supertokens-website sdk you just add it as you normally would to the body, headers etc
r
Perfect, it's look nice πŸ™‚ Many thanks !
n
@RomainJust a slight correction, you would need to override the API to get access to the client id https://supertokens.com/docs/thirdpartyemailpassword/advanced-customizations/apis-override/usage
You can then use our userContext feature to pass it to the function https://supertokens.com/docs/thirdpartyemailpassword/advanced-customizations/user-context
r
Great, thanks to you for your help, I will try to implement this! πŸ™‚
It work very well, but i have to return this in the
signUp
function override, it's a good practice ?
Copy code
throw new EmailPassword.Error({
    type: 'FIELD_ERROR',
    payload: [
        {
        id: 'password',
        error: 'Password must contain at least 12 character',
        },
    ],
    message: 'Error in input formFields',
})
@nkshah2 πŸ™‚
n
You should return with status field error (the api spec can help here)
Other than that it’s fine
r
It's not a status field error here ?
n
Ah right my mistake, yeah that works fine
r
Perfect thanks πŸ™‚