open-condo-software / condo

Open source condominium management platform
MIT License
62 stars 26 forks source link

feat(keystone): DOMA-9790 added extended auth strategy for a specific condo apps logic #5018

Closed Alllex202 closed 1 month ago

Alllex202 commented 1 month ago

Added extended authentication strategy specific to condo applications

Based on PasswordAuthStrategy from @keystonejs/auth-password

What are the differences with the main version?

These features are configurable via config

Example config:

{
    // default props from "@keystonejs/auth-password"
    identityField: 'email',
    secretField: 'password',
    protectIdentities: true,

    // custom props
    findIdentityItems: async function (config, list, args) {
        const { identityField } = config
        const identity = args[identityField]
        return await list.adapter.find({
            [identityField]: identity,
        })
    },
}

in this pr a check for soft-deleted users was added to prepareKeystone

If you need to add your own checks for a specific app, you can do this by overriding findIdentityItems in this way:

    prepareKeystone({
        authStrategyOpts: { 
            config: { 
                findIdentityItems: async (config, list, args) => {
                    const { identityField } = config
                    const identity = args[identityField]
                    return await list.adapter.find({
                        [identityField]: identity,
                        deletedAt: null,
                    })
                }
            },
        },
        ...<other props>
    })
sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud