Hi, I have supertokens setup on my api to allow us...
# general
m
Hi, I have supertokens setup on my api to allow users to create an account, but the data is stored using my own DB... was wondering if it's possible to do the same with ThirdParty?
r
Can you elaborate? If you are using the self hosted version, ALL info generated by supertokens is stored in your db.
m
That is correct, but when attempting to use ThirdParty, it doesn't create data within my DB
r
Which thirdparty provider?
m
Google
r
So it would create the info in thirdparty_users table
m
It provides me with the session
within my own DB?
r
Yes.
m
when I mean my own DB, I don't mean Supertokens db
r
Hmm.
n
I believe the question is: is there a way to easily allow the ThirdParty recipe to add the user details to a application DB, without having to write a lengthy override
m
^^
r
Ah i see. Well. You have to use the override functions to do it.
n
I'm working with @User and IMO, at this point it would be easier for him to create his own Oauth flow to authenticate users, and use the Sessions management he's already set up
ah ok
yes as I thought
r
Ah. Why is using the override function difficult? If you describe your use case and which language, I can give you the code snippet for it
n
Using NestJS typescript. He wants to be able to authorise a user with their google account, create a row for them in the app DB, and then give them a session with a custom payload depending on some business logic/user attributes from the app DB
and the userId in the session token would be the userId generated and stored into his app DB
r
Alright. Will send over code snippet soon
n
thanks
m
Thanks 🙏
r
You can save info in your own db like this and even modify the access token payload like this:
Copy code
ts
ThirdParty.init({
    signInAndUpFeature: {
        providers: [...]
    },
    override: {
        apis: (oI) => {
            return {
                ...oI,
                signInUpPOST: async function (input) {
                    if (oI.signInUpPOST === undefined) {
                        throw Error("Should never come here")
                    }
                    let resp = await oI.signInUpPOST(input);
                    if (resp.status === "OK") {
                        if (resp.createdNewUser) {
                            let googleAccessToken = resp.authCodeResponse["access_token"];
                            let user = resp.user;
                            let session = resp.session;

                            // TODO: store info about the user in your own db

                            // TODO: You can modify the access token payload like this:
                            await session.updateAccessTokenPayload({
                                "someKey": "someValue"
                            })
                        }
                    }
                    return resp;
                }
            }
        }
    }
})
(Assuming you are using thirdparty recipe)
(And that you want to modify the access token's payload only if it's a new user. If you want to modify it regardless, then you can move the
session.updateAccessTokenPayload
part outside the
if
statement that is enclosing it.
m
Cool it works! Thanks
r
Great!