Question - whats the best pattern for implementing a post signup event, and similarly whats the best...
n
Question - whats the best pattern for implementing a post signup event, and similarly whats the best pattern for fetching the user after signin (in particular if the user data is stored in a different custom table) and adding the user data to the req.session. Effectively when someone signs up I'd like to create a custom user entity in a different table, and then fetch it again whenever the session is created or refreshed and make it available on the request
r
hey!
which recipe do you use?
n
email password, or email password socials
r
so thirdpartyemailpassword right?
n
thats the one
r
which backend SDK?
n
nodejs
r
Copy code
ts
ThirdPartyEmailPassword.init({
    override: {
        functions: (oI) => {
            return {
                ...oI,
                emailPasswordSignUp: async function (input) {
                    let resp = await oI.emailPasswordSignUp(input);
                    if (resp.status === "OK") {
                        // TODO: add new email password user to your db
                        // you can even access the request object using input.userContext._default.request
                    }
                    return resp;
                },
                thirdPartySignInUp: async function (input) {
                    let resp = await oI.thirdPartySignInUp(input);
                    if (resp.createdNewUser) {
                        // TODO: add new social login user to your db
                        // you can even access the request object using input.userContext._default.request
                    }
                    return resp;
                }
            }
        }
    }
})

Session.init({
    override: {
        functions: (oI) => {
            return {
                ...oI,
                createNewSession: async function (input) {
                    let userId = input.userId;
                    let infoFromDb = // query your db
                        input.accessTokenPayload = {
                            ...input.accessTokenPayload,
                            "customKey": "customVal"
                        }
                    return oI.createNewSession(input);
                }
            }
        }
    }
})
n
Sweet cheers, I'll give that a crack
3 Views