https://supertokens.com/ logo
override order
s

splinteer

04/16/2023, 5:15 PM
Hello, I have a problem with signup. I have overrided the ThirdPartyEmailPassword recipe to create the user in my personnal db. I also use jwt for the Session and I add credentials to the token payload (like firstname lastname...). The problem is that on registration, the session is called before the user is created in the ThirdPartyEmailPassword recipe. How to make it wait for the user to be created on creation? I don't want to add a loop to check if the user is available Thank you
r

rp

04/17/2023, 5:48 AM
hey @splinteer instead of overriding the override.apis, consider overriding the override.functions config. When you call the original implementation of the apis, it calls the sign up function and also the create new session function
s

splinteer

04/17/2023, 6:33 AM
Hello, thank you for your reply. Do you have an example of this implementation in the doc ?
s

splinteer

04/18/2023, 7:36 PM
Is there a way to get the social access_token using the functions overide?
r

rp

04/19/2023, 4:47 AM
If you are using a different recipe, find a similar page in the other recipe
s

splinteer

04/20/2023, 7:47 PM
Yes but the session doesn't wait for the api to be finished before creating it
That's why I wanted to do it in the function override like you mentioned
Here is my code: apis: (originalImplementation) => { return { ...originalImplementation, thirdPartySignInUpPOST: async function (input) { if ( originalImplementation.thirdPartySignInUpPOST === undefined ) { throw Error('Should never come here'); } // First we call the original implementation of thirdPartySignInUpPOST. const response = await originalImplementation.thirdPartySignInUpPOST(input); // Post sign up response, we check if it was successful if (response.status === 'OK') { const { id, email } = response.user; if (response.createdNewUser) { const userInfo = await getSocialUserInfo( response.user.thirdParty, response.authCodeResponse, ); console.log('User creation'); const created = await customerService.create( id, email, userInfo, ); console.log('user created'); // console.log('created', created); } } return response; }, }; }, },
Session.init({ jwt: { enable: true, }, override: { functions: function (originalImplementation) { return { ...originalImplementation, createNewSession: async function (input) { console.log('Get customer credentials'); const customer = await customerService.getCustomerCredentials( input.userId, ); input.accessTokenPayload = { ...input.accessTokenPayload, customer, }; return originalImplementation.createNewSession(input); }, }; }, }, }), And here is the console output: Get customer credentials User creation user created
r

rp

04/21/2023, 5:23 AM
sorry, im a bit confused - what's the question / issue here?
s

splinteer

04/21/2023, 8:44 AM
My first message explain the problem. The session override function is called before the recipe api override.
Is there a way to make the session wait for the api function or is there a way to tell the session (in the front) to get the latest version of the user accès token payload
r

rp

04/21/2023, 10:48 AM
you should override the override.functions instead of override.apis
s

splinteer

04/21/2023, 10:26 PM
I tried but I can’t get the social access token in right ?
r

rp

04/22/2023, 5:41 AM
Right. In that case, you should use the functions on the session object in the APIs override to manipulate the session data.
Like session.mergeIntoAccessTokenPayload
s

splinteer

04/22/2023, 10:59 AM
Ok thanks, I'll try it