supertokens / supertokens-node

Node SDK for SuperTokens core
https://supertokens.com
Other
292 stars 79 forks source link

Is it possible to strongly type the `firstFactors` option in the MFA Recipe? #830

Closed Lehoczky-peakfs closed 4 months ago

Lehoczky-peakfs commented 4 months ago

Hey there 👋

While working with the MFA recipe, it is possible to have a typo when someone is declaring the firstFactors option:

MultiFactorAuth.init({
    firstFactors: ["emailpassworld"] // typo, should be "emailpassword"
})

Is it possible to change the type of this field? Right now, it is string[], but it could be a string literal union instead, and only allow values from the FactorIds object.

If it is not ideal, another improvement could be to use the FactorIds object in the documentation examples, like this:

import supertokens from "supertokens-node";
import MultiFactorAuth from "supertokens-node/recipe/multifactorauth"

supertokens.init({
   // ...
    recipeList: [
        // ...
        MultiFactorAuth.init({
            firstFactors: [
                MultiFactorAuth.FactorIds.EMAILPASSWORD,
                MultiFactorAuth.FactorIds.THIRDPARTY,
            ]
        })
    ]
})

What do you think? I'm happy to contribute either change if accepted.

rishabhpoddar commented 4 months ago

Hey @Lehoczky-peakfs we did not add strongly typed literals cause we want to allow users to add their own custom factor IDs as well.

As per the docs update, I agree. We should use the ENUMS defined in the lib, and not strings. Keeping this issue open until that is done.

Thanks