idanto
11/13/2023, 12:56 PMThis should never happen: session and user mismatch
the scenario is we have a primary passwordless user and now we want to connect a social media login account (FB in this case).
any directions? I assume it is somehow related to the fact we do the linking in thirdPartySignInUpPOST
and return the response from originalImplementation.thirdPartySignInUpPOST
idanto
11/13/2023, 12:58 PMrp_st
11/13/2023, 12:59 PMidanto
11/13/2023, 1:00 PMrp_st
11/13/2023, 1:01 PMidanto
11/13/2023, 1:02 PMidanto
11/13/2023, 1:02 PMrp_st
11/13/2023, 1:04 PMsession
object you get with getSession points to the currently logged in user's session.
When you call thirdPartySignInUpPOST
, it creates a new session (overwriting the existing one), and also creates a new user that has a new user ID. So when you call linkAccounts
with the (older) session's user ID and then response from thirdPartySignInUpPOST
, you see the mismatch errorrp_st
11/13/2023, 1:05 PMidanto
11/13/2023, 1:05 PMrp_st
11/13/2023, 1:05 PMthirdPartySignInUpPOST
in the API, but it is one way to get it to work.idanto
11/13/2023, 1:06 PMrp_st
11/13/2023, 1:06 PMrp_st
11/13/2023, 1:07 PMoriginalImplementation.thirdPartySignInUpPOST
, and instead do what i linkedidanto
11/13/2023, 1:07 PMidanto
11/13/2023, 1:07 PMidanto
11/13/2023, 1:08 PMrp_st
11/13/2023, 1:09 PMidanto
11/13/2023, 1:10 PMrp_st
11/13/2023, 1:11 PMoriginalImplementation.thirdPartySignInUpPOST
to signify that a session already exists, and then in the createNewSession override, just return the existing session if that userContext has itrp_st
11/13/2023, 1:11 PMidanto
11/13/2023, 1:13 PMrp_st
11/13/2023, 1:42 PMrp_st
11/13/2023, 1:42 PMidanto
11/13/2023, 1:42 PMinput.userContext.session = session;
where session is the response of:
const session = await Session.getSession(
input.options.req,
input.options.res,
);
and we send the input to:
const response =
await originalImplementation.thirdPartySignInUpPOST(input);
rp_st
11/13/2023, 1:42 PMidanto
11/13/2023, 1:47 PMrp_st
11/13/2023, 1:48 PMidanto
11/13/2023, 1:48 PMidanto
11/13/2023, 1:49 PMinput.userContext.session = session;
rp_st
11/13/2023, 1:49 PMidanto
11/13/2023, 1:51 PMthirdPartySignInUp: async (input) => {
const response = await originalImplementation.thirdPartySignInUp(input);
if (response.status === 'OK') {
const userInfo =
(this.configService.get<string>('NODE_ENV') === 'development' &&
JSON.stringify(response.user)) ||
response.user.id;
if (response.createdNewRecipeUser) {
// TODO: some post sign up logic
this.logger.log(
`successful thirdparty function sign-up ${userInfo}`,
);
await this.newUserCallback(response.user);
} else {
// TODO: some post sign in logic
this.logger.log(`successful thirdparty sign-in ${userInfo}`);
}
} else {
this.logger.error(
`failed thirdparty sign-in/up Status:${response.status}`,
);
}
return response;
},
rp_st
11/13/2023, 1:51 PMidanto
11/13/2023, 1:54 PMidanto
11/13/2023, 1:54 PMidanto
11/13/2023, 1:54 PMidanto
11/13/2023, 2:03 PMidanto
11/13/2023, 2:04 PMidanto
11/13/2023, 2:32 PMrp_st
11/13/2023, 2:32 PMidanto
11/13/2023, 2:33 PMrp_st
11/13/2023, 2:34 PMidanto
11/13/2023, 2:34 PM(response.user.thirdParty as any) = {
...response.user.thirdParty,
accessToken,
}
and it is even being logged in the last log before we return the responseidanto
11/13/2023, 2:34 PMrp_st
11/13/2023, 2:38 PMrp_st
11/13/2023, 2:39 PMidanto
11/13/2023, 2:39 PMidanto
11/13/2023, 2:39 PMrp_st
11/13/2023, 2:40 PMidanto
11/13/2023, 2:41 PMthirdPartySignInUp
api, right?rp_st
11/13/2023, 2:42 PMidanto
11/13/2023, 2:45 PMthirdPartySignInUp: async (input) => {
const response = await originalImplementation.thirdPartySignInUp(input);
this.logger.log({
msg: 'response from internal implementation',
response,
});
return response;
},
idanto
11/13/2023, 2:46 PMrp_st
11/13/2023, 2:47 PMidanto
11/13/2023, 2:48 PMidanto
11/13/2023, 2:48 PMrp_st
11/13/2023, 2:49 PMidanto
11/13/2023, 2:51 PMidanto
11/13/2023, 2:52 PMrp_st
11/13/2023, 2:52 PM