fdundjer
08/15/2023, 1:18 PMrp_st
08/15/2023, 1:20 PMfdundjer
08/15/2023, 1:23 PMresult = await executeSupertokensApiRequest(
`/${tenantId}/signinup/code`,
{
phoneNumber: testUserPhoneNumber,
},
'POST',
{
rid: 'passwordless',
Authorization: `Bearer ${accessToken}`,
},
);
The key here is that we are passing authorization header where we use the token that we got from previous request.
Since we want to avoid writing raw http request, we are wondering if this can be achieved by SDK.rp_st
08/15/2023, 1:27 PMrp_st
08/15/2023, 1:28 PMfdundjer
08/15/2023, 1:33 PM/*This API is called to send an OTP*/
createCodePOST: async function (input) {
/**
* We want to make sure that the OTP being generated is for the
* same number that belongs to this user.
*/
// A session should already exist since this should be called after the first factor is completed.
// We remove claim checking here, since this needs to be callable without the second factor completed
let session = await Session.getSession(input.options.req, input.options.res, {
overrideGlobalClaimValidators: () => [],
});
let phoneNumber: string = session!.getAccessTokenPayload().phoneNumber;
if (phoneNumber !== undefined) {
// this means we found a phone number associated to this user.
// we will check if the input phone number is the same as this one.
if (!("phoneNumber" in input) || input.phoneNumber !== phoneNumber) {
throw new Error("Input phone number is not the same as the one saved for this user");
}
}
return oI.createCodePOST!(input);
},
it requires session.
Frontend team is using this library: https://github.com/supertokens/supertokens-web-jsrp_st
08/15/2023, 1:34 PMfdundjer
08/15/2023, 1:38 PMrp_st
08/15/2023, 1:40 PMfdundjer
08/15/2023, 1:59 PMsbugarski
08/15/2023, 3:42 PMSuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).
Powered by