[Manicraft1001]
05/05/2022, 6:26 PMrp_st
05/05/2022, 6:28 PMrp_st
05/05/2022, 6:29 PMrp_st
05/05/2022, 6:29 PMrp_st
05/05/2022, 6:36 PM[Manicraft1001]
05/05/2022, 6:37 PM[Manicraft1001]
05/08/2022, 3:51 PMjavascript
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
emailPasswordSignUp(input) {
console.log(`emailPasswordSignUp`);
console.log(input);
return originalImplementation.emailPasswordSignUp(input);
},
}
},
Form fields on the server side:
javascript
signUpFeature: {
formFields: [
{
id: "username",
},
],
},
Form fields on the frontend:
javascript
signUpForm: {
formFields: [
{
id: "username",
label: "Username",
placeholder: "Public visible username",
},
],
termsOfServiceLink: "https://example.com/terms-of-service",
privacyPolicyLink: "https://example.com/privacy-policy",
},
There is no information about the form fields in the request:
emailPasswordSignUp
{
email: 'manicraft25@gmail.com',
password: 'sml12345',
userContext: {}
}
rp_st
05/08/2022, 4:02 PMrp_st
05/08/2022, 4:02 PMrp_st
05/08/2022, 4:04 PMoverride: {
apis: (originalImplementation) => {
return {
...originalImplementation,
emailPasswordSignUpPOST: async function (input) {
// Your logic here. The input variable will contain all the form fields
}
}
}
}
[Manicraft1001]
05/08/2022, 4:19 PMrp_st
05/08/2022, 4:20 PMsignUp
recipe function override.[Manicraft1001]
05/08/2022, 4:30 PMjavascript
export const backendConfig = (): TypeInput => {
return {
framework: "express",
supertokens: {
connectionURI: "<REDACTED>",
apiKey: process.env.SUPERTOKENS_API_KEY,
},
appInfo,
recipeList: [
ThirdPartyEmailPasswordNode.init({
providers: [
// We have provided you with development keys which you can use for testsing.
// IMPORTANT: Please replace them with your own OAuth keys for production use.
ThirdPartyEmailPasswordNode.Google({
clientId:
"<REDACTED>",
clientSecret: "<REDACTED></REDACTED>",
}),
],
signUpFeature: {
formFields: [
{
id: "username",
},
],
},
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
emailPasswordSignUp(input) {
const usernameFromContext = input.userContext.username;
console.log("usernameFromContext", usernameFromContext);
return originalImplementation.emailPasswordSignUp(input);
},
};
},
apis: (originalImplementation) => {
return {
...originalImplementation,
emailPasswordSignUpPOST: async function (input) {
if (
originalImplementation.emailPasswordSignUpPOST === undefined
) {
throw Error("Should never come here");
}
// First we call the original implementation
let response =
await originalImplementation.emailPasswordSignUpPOST(input);
// If sign up was successful
if (response.status === "OK") {
// We can get the form fields from the input like this
let formFields = input.formFields;
let user = response.user;
console.log(formFields);
const fieldUsername = formFields.find(
(field) => field.id === "username"
);
input.userContext.username = fieldUsername?.value;
}
return response;
},
};
},
},
}),
SessionNode.init({
override: {
functions: (originalImplementation) => {
return {
...originalImplementation,
createNewSession: async function (input) {
let userId = input.userId;
console.log(input.userContext);
const username = "todo";
// This goes in the access token, and is availble to read on the frontend.
input.accessTokenPayload = {
...input.accessTokenPayload,
username: username,
};
// This is stored in the db against the sessionHandle for this session
input.sessionData = {
...input.sessionData,
username: username,
};
const session = originalImplementation.createNewSession(input);
console.log(`user ${userId} created a new session`);
return session;
},
};
},
},
}),
],
isInServerlessEnv: true,
};
};
Context in ``emailPasswordSignUp`` still seems to be undefined.
usernameFromContext undefined
{}
user 92c11c44-308d-4ef9-b504-35f19d43a1ff created a new session
[
{ id: 'email', value: 'manicraft27@gmail.com' },
{ id: 'password', value: 'sml12345' },
{ id: 'username', value: 'Mani27' }
]
I also can't find an example in the documentation, even tho this is a common customisation.rp_st
05/08/2022, 4:31 PMrp_st
05/08/2022, 4:32 PM[Manicraft1001]
05/08/2022, 4:34 PM[Manicraft1001]
05/08/2022, 5: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