Skip to content

Commit

Permalink
feat: review discussions/comments
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed May 21, 2024
1 parent 630eab8 commit 4d642d4
Show file tree
Hide file tree
Showing 78 changed files with 476 additions and 784 deletions.
285 changes: 1 addition & 284 deletions examples/for-tests-react-16/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import EmailVerification from "supertokens-auth-react/recipe/emailverification";
import EmailPassword from "supertokens-auth-react/recipe/emailpassword";
import Passwordless from "supertokens-auth-react/recipe/passwordless";
import ThirdParty from "supertokens-auth-react/recipe/thirdparty";
import ThirdPartyEmailPassword from "supertokens-auth-react/recipe/thirdpartyemailpassword";
import ThirdPartyPasswordless from "supertokens-auth-react/recipe/thirdpartypasswordless";
import UserRoles from "supertokens-auth-react/recipe/userroles";
import Multitenancy from "supertokens-auth-react/recipe/multitenancy";
import MultiFactorAuth from "supertokens-auth-react/recipe/multifactorauth";
Expand Down Expand Up @@ -255,15 +253,9 @@ if (enabledRecipes.includes("thirdparty")) {
if (enabledRecipes.includes("emailpassword")) {
recipeList = [getEmailPasswordConfigs(testContext), ...recipeList];
}
if (enabledRecipes.includes("thirdpartyemailpassword")) {
recipeList = [getThirdPartyEmailPasswordConfigs(testContext), ...recipeList];
}
if (enabledRecipes.includes("passwordless")) {
recipeList = [getPasswordlessConfigs(testContext), ...recipeList];
}
if (enabledRecipes.includes("thirdpartypasswordless")) {
recipeList = [getThirdPartyPasswordlessConfigs(testContext), ...recipeList];
}

if (emailVerificationMode !== "OFF") {
recipeList.push(getEmailVerificationConfigs(testContext));
Expand Down Expand Up @@ -302,8 +294,6 @@ SuperTokens.init({
emailpassword: "EMAIL_PASSWORD",
thirdparty: "THIRD_PARTY",
passwordless: "PASSWORDLESS",
thirdpartypasswordless: "THIRDPARTYPASSWORDLESS",
thirdpartyemailpassword: "THIRD_PARTY_EMAIL_PASSWORD",
}[context.recipeId];

console.log(`ST_LOGS SUPERTOKENS GET_REDIRECTION_URL SUCCESS ${logId}`);
Expand All @@ -320,6 +310,7 @@ SuperTokens.init({
privacyPolicyLink: "https://supertokens.com/legal/privacy-policy",
termsOfServiceLink: "https://supertokens.com/legal/terms-and-conditions",
defaultToSignUp,
disableAuthRoute: testContext.disableDefaultUI,
recipeList,
});

Expand Down Expand Up @@ -436,12 +427,8 @@ export function DashboardHelper({ redirectOnLogout, ...props } = {}) {
const useRecipe = getQueryParams("rid") || authRecipe;
if (useRecipe === "thirdparty") {
await ThirdParty.signOut();
} else if (useRecipe === "thirdpartyemailpassword") {
await ThirdPartyEmailPassword.signOut();
} else if (useRecipe === "passwordless") {
await Passwordless.signOut();
} else if (useRecipe === "thirdpartypasswordless") {
await ThirdPartyPasswordless.signOut();
} else {
await EmailPassword.signOut();
}
Expand Down Expand Up @@ -641,7 +628,6 @@ function getEmailPasswordConfigs({ disableDefaultUI }) {
},
},
signInAndUpFeature: {
disableDefaultUI,
signInForm: {
style: theme.style,
},
Expand All @@ -653,124 +639,6 @@ function getEmailPasswordConfigs({ disableDefaultUI }) {
});
}

function getThirdPartyPasswordlessConfigs({ staticProviderList, disableDefaultUI, thirdPartyRedirectURL }) {
let providers = [
ThirdParty.Github.init(),
ThirdParty.Google.init(),
ThirdParty.Facebook.init(),
ThirdParty.Apple.init(),
{
id: "custom",
name: "Custom",
},
{
id: "auth0",
name: "Auth0",
getRedirectURL: thirdPartyRedirectURL !== null ? () => thirdPartyRedirectURL : undefined,
},
{
id: "mock-provider",
name: "Mock Provider",
},
];
if (staticProviderList) {
const ids = JSON.parse(staticProviderList);
providers = ids.map((id) => providers.find((p) => p.id === id) || { id, name: id });
}

return ThirdPartyPasswordless.init({
override: {
functions: (implementation) => {
const log = logWithPrefix(`ST_LOGS THIRDPARTYPASSWORDLESS OVERRIDE`);

return {
...implementation,
doesPasswordlessUserEmailExist(...args) {
log(`DOES_PASSWORDLESS_USER_EMAIL_EXIST`);
return implementation.doesPasswordlessUserEmailExist(...args);
},
doesPasswordlessUserPhoneNumberExist(...args) {
log(`DOES_PASSWORDLESS_USER_PHONE_NUMBER_EXIST`);
return implementation.doesPasswordlessUserPhoneNumberExist(...args);
},
createPasswordlessCode(...args) {
log(`CREATE_CODE`);
return implementation.createPasswordlessCode(...args);
},
resendPasswordlessCode(...args) {
log(`RESEND_CODE`);
return implementation.resendPasswordlessCode(...args);
},
consumePasswordlessCode(...args) {
log(`CONSUME_CODE`);
return implementation.consumePasswordlessCode(...args);
},
getPasswordlessLoginAttemptInfo(...args) {
log(`GET_LOGIN_ATTEMPT_INFO`);
return implementation.getPasswordlessLoginAttemptInfo(...args);
},
setPasswordlessLoginAttemptInfo(...args) {
log(`SET_LOGIN_ATTEMPT_INFO`);
return implementation.setPasswordlessLoginAttemptInfo(...args);
},
clearPasswordlessLoginAttemptInfo(...args) {
log(`CLEAR_LOGIN_ATTEMPT_INFO`);
return implementation.clearPasswordlessLoginAttemptInfo(...args);
},
getThirdPartyStateAndOtherInfoFromStorage(...args) {
log(`GET_OAUTH_STATE`);
return implementation.getThirdPartyStateAndOtherInfoFromStorage(...args);
},
getThirdPartyAuthorisationURLWithQueryParamsAndSetState(...args) {
log(`GET_AUTH_URL_WITH_QUERY_PARAMS_AND_SET_STATE`);
return implementation.getThirdPartyAuthorisationURLWithQueryParamsAndSetState(...args);
},
setThirdPartyStateAndOtherInfoToStorage(...args) {
log(`SET_OAUTH_STATE`);
return implementation.setThirdPartyStateAndOtherInfoToStorage(...args);
},
thirdPartySignInAndUp(...args) {
log(`THIRD_PARTY_SIGN_IN_AND_UP`);
return implementation.thirdPartySignInAndUp(...args);
},
};
},
},
preAPIHook: async (context) => {
console.log(`ST_LOGS THIRDPARTYPASSWORDLESS PRE_API_HOOKS ${context.action}`);
return context;
},
getRedirectionURL: async (context) => {
console.log(`ST_LOGS THIRDPARTYPASSWORDLESS GET_REDIRECTION_URL ${context.action}`);
},
onHandleEvent: async (context) => {
console.log(`ST_LOGS THIRDPARTYPASSWORDLESS ON_HANDLE_EVENT ${context.action}`);
},
contactMethod: passwordlessContactMethodType,
disablePasswordless: false,
signInUpFeature: {
disableDefaultUI,
style: theme.style,
thirdPartyProviderAndEmailOrPhoneFormStyle: `
[data-supertokens~=providerCustom] {
color: red;
},
`,
providers,
defaultCountry: passwordlessDefaultCountry,
resendEmailOrSMSGapInSeconds: 2,
},
linkClickedScreenFeature: {
disableDefaultUI,
style: theme.style,
},
mfaFeature: {
disableDefaultUI,
style: theme,
},
});
}

function getPasswordlessConfigs({ disableDefaultUI, defautToEmail }) {
return Passwordless.init({
override: {
Expand Down Expand Up @@ -828,7 +696,6 @@ function getPasswordlessConfigs({ disableDefaultUI, defautToEmail }) {
signInUpFeature: {
defaultCountry: passwordlessDefaultCountry,
resendEmailOrSMSGapInSeconds: 2,
disableDefaultUI,
style: theme.style,
defautToEmail,
},
Expand Down Expand Up @@ -910,159 +777,9 @@ function getThirdPartyConfigs({ staticProviderList, disableDefaultUI, thirdParty
},
},
signInAndUpFeature: {
disableDefaultUI,
style: theme.style,
providers,
},

oAuthCallbackScreen: {
style: theme.style,
},
});
}

function getThirdPartyEmailPasswordConfigs({ staticProviderList, disableDefaultUI, thirdPartyRedirectURL }) {
let providers = [
ThirdParty.Github.init(),
ThirdParty.Google.init(),
ThirdParty.Facebook.init(),
ThirdParty.Apple.init(),
{
id: "custom",
name: "Custom",
},
{
id: "auth0",
name: "Auth0",
getRedirectURL: thirdPartyRedirectURL !== null ? () => thirdPartyRedirectURL : undefined,
},
{
id: "mock-provider",
name: "Mock Provider",
},
];
if (staticProviderList) {
const ids = JSON.parse(staticProviderList);
providers = ids.map((id) => providers.find((p) => p.id === id) || { id, name: id });
}
return ThirdPartyEmailPassword.init({
preAPIHook: async (context) => {
console.log(`ST_LOGS THIRD_PARTY_EMAIL_PASSWORD PRE_API_HOOKS ${context.action}`);
return context;
},
getRedirectionURL: async (context) => {
console.log(`ST_LOGS THIRD_PARTY_EMAIL_PASSWORD GET_REDIRECTION_URL ${context.action}`);
if (context.action === "SUCCESS") {
setIsNewUserToStorage("thirdpartyemailpassword", context.isNewRecipeUser);
return context.redirectToPath || "/dashboard";
}
},
onHandleEvent: async (context) => {
console.log(`ST_LOGS THIRD_PARTY_EMAIL_PASSWORD ON_HANDLE_EVENT ${context.action}`);
},
override: {
functions: (implementation) => {
const log = logWithPrefix(`ST_LOGS THIRD_PARTY_EMAIL_PASSWORD OVERRIDE`);

return {
...implementation,
getAuthorisationURLWithQueryParamsAndSetState(input) {
if (input.userContext["key"] !== undefined) {
log(`GET_AUTH_URL_WITH_QUERY_PARAMS_AND_SET_STATE RECEIVED_USER_CONTEXT`);
}

log(`GET_AUTH_URL_WITH_QUERY_PARAMS_AND_SET_STATE`);
return implementation.getAuthorisationURLWithQueryParamsAndSetState(input);
},
thirdPartySignInAndUp(input) {
if (input.userContext["key"] !== undefined) {
log(`SIGN_IN_AND_UP RECEIVED_USER_CONTEXT`);
}

log(`SIGN_IN_AND_UP`);
return implementation.thirdPartySignInAndUp(input);
},
emailPasswordSignIn(...args) {
log(`SIGN_IN_AND_UP`);
return implementation.emailPasswordSignIn(...args);
},
emailPasswordSignUp(...args) {
log(`SIGN_IN_AND_UP`);
return implementation.emailPasswordSignUp(...args);
},
setStateAndOtherInfoToStorage(input) {
if (input.userContext["key"] !== undefined) {
log(`SET_OAUTH_STATE RECEIVED_USER_CONTEXT`);
}

log(`SET_OAUTH_STATE`);
return implementation.setStateAndOtherInfoToStorage(input);
},
getStateAndOtherInfoFromStorage(input) {
if (input.userContext["key"] !== undefined) {
log(`GET_OAUTH_STATE RECEIVED_USER_CONTEXT`);
}

log(`GET_OAUTH_STATE`);
return implementation.getStateAndOtherInfoFromStorage(input);
},
submitNewPassword(input) {
if (input.userContext["key"] !== undefined) {
log(`SUBMIT_NEW_PASSWORD RECEIVED_USER_CONTEXT`);
}

log(`SUBMIT_NEW_PASSWORD`);
return implementation.submitNewPassword(input);
},
sendPasswordResetEmail(input) {
if (input.userContext["key"] !== undefined) {
log(`SEND_PASSWORD_RESET_EMAIL RECEIVED_USER_CONTEXT`);
}

log(`SEND_PASSWORD_RESET_EMAIL`);
return implementation.sendPasswordResetEmail(input);
},
getResetPasswordTokenFromURL(input) {
if (input.userContext["key"] !== undefined) {
log(`GET_RESET_TOKEN_FROM_URL RECEIVED_USER_CONTEXT`);
}

return implementation.getResetPasswordTokenFromURL(input);
},
doesEmailExist(...args) {
log(`DOES_EMAIL_EXIST`);
return implementation.doesEmailExist(...args);
},
getAuthStateFromURL(input) {
if (input.userContext["key"] !== undefined) {
log(`GET_AUTH_STATE_FROM_URL RECEIVED_USER_CONTEXT`);
}

return implementation.getAuthStateFromURL(input);
},
verifyAndGetStateOrThrowError(input) {
if (input.userContext["key"] !== undefined) {
log(`VERIFY_STATE RECEIVED_USER_CONTEXT`);
}

return implementation.verifyAndGetStateOrThrowError(input);
},
};
},
},
resetPasswordUsingTokenFeature: {
disableDefaultUI,
},
signInAndUpFeature: {
disableDefaultUI,
signInForm: {},
signUpForm: {
formFields,
},
style: theme.style,
providers,
},
disableEmailPassword: false,

oAuthCallbackScreen: {
style: theme.style,
Expand Down
16 changes: 15 additions & 1 deletion examples/for-tests-react-16/src/AppWithReactDomRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,21 @@ function AppWithReactDomRouter(props) {
<Route path="/contact" element={<Contact />} />
<Route
path="/custom-supertokens-login"
element={<AuthPage preBuiltUIList={[EmailPasswordPreBuiltUI]} />}
element={
<AuthPage factors={["emailpassword"]} preBuiltUIList={[EmailPasswordPreBuiltUI]} />
}
/>
<Route
path="/auth-for-factors"
element={
<AuthPage
preBuiltUIList={recipePreBuiltUIList}
userContext={{
key: "value",
}}
factors={new URLSearchParams(window.location.search).get("factors")?.split(",")}
/>
}
/>

{/* User context paths */}
Expand Down
Loading

0 comments on commit 4d642d4

Please sign in to comment.