https://supertokens.com/ logo
#general
Title
# general
m

Marques

03/14/2022, 4:13 PM
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

rp

03/14/2022, 4:17 PM
Can you elaborate? If you are using the self hosted version, ALL info generated by supertokens is stored in your db.
m

Marques

03/14/2022, 4:18 PM
That is correct, but when attempting to use ThirdParty, it doesn't create data within my DB
r

rp

03/14/2022, 4:19 PM
Which thirdparty provider?
m

Marques

03/14/2022, 4:19 PM
Google
r

rp

03/14/2022, 4:19 PM
So it would create the info in thirdparty_users table
m

Marques

03/14/2022, 4:19 PM
It provides me with the session
within my own DB?
r

rp

03/14/2022, 4:20 PM
Yes.
m

Marques

03/14/2022, 4:24 PM
when I mean my own DB, I don't mean Supertokens db
r

rp

03/14/2022, 4:25 PM
Hmm.
n

Naf

03/14/2022, 4:26 PM
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

Marques

03/14/2022, 4:27 PM
^^
r

rp

03/14/2022, 4:27 PM
Ah i see. Well. You have to use the override functions to do it.
n

Naf

03/14/2022, 4:27 PM
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

rp

03/14/2022, 4:28 PM
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

Naf

03/14/2022, 4:31 PM
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

rp

03/14/2022, 4:31 PM
Alright. Will send over code snippet soon
n

Naf

03/14/2022, 4:31 PM
thanks
m

Marques

03/14/2022, 4:32 PM
Thanks 🙏
r

rp

03/14/2022, 4:50 PM
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

Marques

03/14/2022, 5:44 PM
Cool it works! Thanks
r

rp

03/14/2022, 5:44 PM
Great!