bolg55
02/17/2024, 6:53 PMts
import { db } from '@db/index';
import { users, profiles } from '@db/schema';
const thirdPartySignInUpOverride =
(originalImplementation) => async (input) => {
let response = await originalImplementation.thirdPartySignInUp(input);
if (response.status === 'OK') {
let { id, emails } = response.user;
console.log('USER SIGNED UP', id);
await db.transaction(async (trx) => {
await trx.insert(users).values({
id,
email: emails[0],
});
await trx.insert(profiles).values({
userId: id,
});
});
// This is the response from the OAuth 2 provider that contains their tokens or user info.
let providerAccessToken = response.oAuthTokens['access_token'];
let firstName =
response.rawUserInfoFromProvider.fromUserInfoAPI!['first_name'];
if (
response.createdNewRecipeUser &&
response.user.loginMethods.length === 1
) {
// TODO: Post sign up logic
} else {
// TODO: Post sign in logic
}
}
return response;
};
export default thirdPartySignInUpOverride;
I am really not sure of what the originalImplementation
type should be. I have tried creating an interface from ThirdPartyPasswordless recipe, but that didn't work at all. Any ideas?
Edit: Found a way to type using RecipeInterface. Not sure if this is documented? I had to search in discord and got luckyrp_st
02/18/2024, 5:40 AM