Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add storybook #774

Merged
merged 28 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5132f13
ci: add storybook
porcellus Oct 31, 2023
7c7bde4
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Oct 31, 2023
dbb8cfd
Merge branch 'feat/mfa/totp' into feat/mfa/storybook
porcellus Nov 6, 2023
9840df0
ci: update stories after merge
porcellus Nov 6, 2023
745f7e3
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Nov 7, 2023
06fb52a
ci: update&add stories
porcellus Nov 9, 2023
94eb79b
refactor: small code-changes to help storybooks build/work right
porcellus Nov 9, 2023
4fb1b41
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Nov 9, 2023
9fb43a5
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Nov 9, 2023
cd10c4b
Merge branch 'feat/mfa/recipe-setup' into feat/mfa/storybook
porcellus Nov 9, 2023
e222df3
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Nov 9, 2023
805b340
docs: fix usesDynamicLoginMethods control in storybooks
porcellus Nov 10, 2023
ce2ebb2
docs: reset uis properly when re-rendering auth page stories
porcellus Nov 13, 2023
7ec4790
docs: provide better error reporting in auth page stories
porcellus Nov 13, 2023
d5e0321
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Nov 13, 2023
caf708c
Merge remote-tracking branch 'origin/feat/mfa/tests' into feat/mfa/st…
porcellus Nov 15, 2023
989f59e
docs: add separate stories for different button configs in totp
porcellus Nov 15, 2023
94cde46
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Nov 21, 2023
2aa8dd0
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Nov 21, 2023
6cb22bd
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Dec 4, 2023
2a412d4
test: add stories for auth recipe screens
porcellus Dec 6, 2023
cfc414e
Merge branch 'feat/mfa/tests' into feat/mfa/storybook
porcellus Dec 6, 2023
24dbe36
fix: type fixes and design updates + extended storybook
porcellus Dec 7, 2023
477cc09
test: make tests backward compatible
porcellus Dec 8, 2023
a47eda3
fix: fix recipe name in error message
porcellus Dec 8, 2023
35e54ca
test: fix enableMFA
porcellus Dec 8, 2023
77f1e21
Merge remote-tracking branch 'origin/feat/mfa/tests' into feat/mfa/st…
porcellus Dec 8, 2023
184b8fe
Merge remote-tracking branch 'origin/feat/mfa/tests' into feat/mfa/st…
porcellus Dec 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"presets": [["@babel/preset-env", {}, "@babel/preset-react"]],
"plugins": [
"presets": [
"@babel/preset-env",
[
"@babel/plugin-transform-react-jsx",
"@babel/preset-typescript",
{
"pragmaFrag": "React.Fragment"
"allExtensions": true,
"isTSX": true
}
]
],
["@babel/preset-react", { "runtime": "automatic" }]
]
}
26 changes: 26 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { StorybookConfig } from "@storybook/react-webpack5";
// import '@storybook/addon-console';

const config: StorybookConfig = {
stories: ["../stories/**/*.mdx", "../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-essentials",
"@storybook/addon-actions",
"@storybook/addon-links",
"@storybook/addon-interactions",
"@storybook/addon-designs",
// "@storybook/addon-actions/register",
],
framework: {
name: "@storybook/react-webpack5",
options: {},
},
docs: {
autodocs: false,
},
env: {
REACT_APP_TEST_MODE: "testing",
TEST_MODE: "testing",
},
};
export default config;
16 changes: 16 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Preview } from "@storybook/react";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^(w+.)*on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
boolean: /(is|show|loaded)/i,
},
},
},
};

export default preview;
18 changes: 14 additions & 4 deletions examples/for-tests-react-16/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import ThirdPartyEmailPassword from "supertokens-auth-react/recipe/thirdpartyema
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";
import TOTP from "supertokens-auth-react/recipe/totp";

import axios from "axios";
import { useSessionContext } from "supertokens-auth-react/recipe/session";
Expand Down Expand Up @@ -178,9 +180,7 @@ const formFields = [
const testContext = getTestContext();

let recipeList = [
MultiFactorAuth.init({
firstFactors: testContext.firstFactors,
}),
TOTP.init(),
Multitenancy.init({
override: {
functions: (oI) => ({
Expand Down Expand Up @@ -224,7 +224,7 @@ let recipeList = [
return implementation.doesSessionExist(...args);
},
getAccessTokenPayloadSecurely(...args) {
log(`GET_JWT_PAYLOAD_SECURELY`);
// log(`GET_JWT_PAYLOAD_SECURELY`);
return implementation.getAccessTokenPayloadSecurely(...args);
},
getUserId(...args) {
Expand Down Expand Up @@ -273,6 +273,15 @@ if (enabledRecipes.includes("thirdpartypasswordless")) {
if (emailVerificationMode !== "OFF") {
recipeList.push(getEmailVerificationConfigs(testContext));
}

if (testContext.enableMFA) {
recipeList.push(
MultiFactorAuth.init({
firstFactors: testContext.firstFactors,
})
);
}

SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
Expand Down Expand Up @@ -519,6 +528,7 @@ function SessionInfoTable({ sessionInfo }) {

function getEmailVerificationConfigs({ disableDefaultUI }) {
return EmailVerification.init({
useShadowDom,
disableDefaultUI,
sendVerifyEmailScreen: {
style: theme,
Expand Down
11 changes: 9 additions & 2 deletions examples/for-tests-react-16/src/AppWithReactDomRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ import { EmailPasswordPreBuiltUI } from "supertokens-auth-react/recipe/emailpass
import { PasswordlessPreBuiltUI } from "supertokens-auth-react/recipe/passwordless/prebuiltui";
import { ThirdPartyPreBuiltUI } from "supertokens-auth-react/recipe/thirdparty/prebuiltui";
import { MultiFactorAuthPreBuiltUI } from "supertokens-auth-react/recipe/multifactorauth/prebuiltui";
import { TOTPPreBuiltUI } from "supertokens-auth-react/recipe/totp/prebuiltui";
import { AccessDeniedScreen } from "supertokens-auth-react/recipe/session/prebuiltui";
import { getEnabledRecipes } from "./testContext";
import { getEnabledRecipes, getTestContext } from "./testContext";

function AppWithReactDomRouter(props) {
const context = getTestContext();
const enabledRecipes = getEnabledRecipes();
const emailVerificationMode = window.localStorage.getItem("mode") || "OFF";

let recipePreBuiltUIList = [MultiFactorAuthPreBuiltUI];
let recipePreBuiltUIList = [TOTPPreBuiltUI];
if (enabledRecipes.includes("emailpassword")) {
recipePreBuiltUIList.push(EmailPasswordPreBuiltUI);
}
Expand All @@ -43,6 +45,11 @@ function AppWithReactDomRouter(props) {
if (emailVerificationMode !== "OFF") {
recipePreBuiltUIList.push(EmailVerificationPreBuiltUI);
}

if (context.enableMFA) {
recipePreBuiltUIList.push(MultiFactorAuthPreBuiltUI);
}

/**
* For user context tests we add this query param so the additional routes
* dont interfere with other tests
Expand Down
11 changes: 9 additions & 2 deletions examples/for-tests-react-16/src/AppWithReactDomRouterV5.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import { EmailPasswordPreBuiltUI } from "supertokens-auth-react/recipe/emailpass
import { PasswordlessPreBuiltUI } from "supertokens-auth-react/recipe/passwordless/prebuiltui";
import { ThirdPartyPreBuiltUI } from "supertokens-auth-react/recipe/thirdparty/prebuiltui";
import { AccessDeniedScreen } from "supertokens-auth-react/recipe/session/prebuiltui";
import { getEnabledRecipes } from "./testContext";
import { MultiFactorAuthPreBuiltUI } from "supertokens-auth-react/recipe/multifactorauth/prebuiltui";
import { TOTPPreBuiltUI } from "supertokens-auth-react/recipe/totp/prebuiltui";
import { getEnabledRecipes, getTestContext } from "./testContext";

function AppWithReactDomRouter(props) {
const context = getTestContext();
const enabledRecipes = getEnabledRecipes();
const emailVerificationMode = window.localStorage.getItem("mode") || "OFF";

let recipePreBuiltUIList = [];
let recipePreBuiltUIList = [TOTPPreBuiltUI];
if (enabledRecipes.includes("emailpassword")) {
recipePreBuiltUIList.push(EmailPasswordPreBuiltUI);
}
Expand All @@ -38,6 +41,10 @@ function AppWithReactDomRouter(props) {
recipePreBuiltUIList.push(EmailVerificationPreBuiltUI);
}

if (context.enableMFA) {
recipePreBuiltUIList.push(MultiFactorAuthPreBuiltUI);
}

const websiteBasePath = window.localStorage.getItem("websiteBasePath") || undefined;

const [claimValidators, setClaimValidators] = useState(undefined);
Expand Down
44 changes: 9 additions & 35 deletions examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,40 +333,6 @@ const customFields = [

const testContext = getTestContext();

let storedTOTPDevices = window.localStorage.getItem("totpDevices");
let totpDevices = storedTOTPDevices ? JSON.parse(storedTOTPDevices) : [];

function removeTOTPDevice(deviceName) {
const origLength = totpDevices.length;
totpDevices = totpDevices.filter((d) => d.deviceName !== deviceName);
window.localStorage.setItem("totpDevices", JSON.stringify(totpDevices));
return totpDevices.length !== origLength;
}

function addTOTPDevice(deviceName) {
totpDevices.push({
deviceName,
verified: false,
});
window.localStorage.setItem("totpDevices", JSON.stringify(totpDevices));
}

function verifyTOTPDevice(deviceName) {
totpDevices = totpDevices.filter((d) => d.deviceName !== deviceName);
totpDevices.push({
deviceName,
verified: true,
});
window.localStorage.setItem("totpDevices", JSON.stringify(totpDevices));
}
let tryCount = 0;

setInterval(() => (tryCount = tryCount > 0 ? tryCount - 1 : 0), 30000);
window.resetTOTP = () => {
totpDevices = [];
window.localStorage.setItem("totpDevices", JSON.stringify(totpDevices));
tryCount = 0;
};
let recipeList = [
TOTP.init(),
MultiFactorAuth.init({
Expand Down Expand Up @@ -416,7 +382,7 @@ let recipeList = [
return implementation.doesSessionExist(...args);
},
getAccessTokenPayloadSecurely(...args) {
log(`GET_JWT_PAYLOAD_SECURELY`);
// log(`GET_JWT_PAYLOAD_SECURELY`);
return implementation.getAccessTokenPayloadSecurely(...args);
},
getUserId(...args) {
Expand Down Expand Up @@ -478,6 +444,14 @@ if (emailVerificationMode !== "OFF") {
recipeList.push(getEmailVerificationConfigs(testContext));
}

if (testContext.enableMFA) {
recipeList.push(
MultiFactorAuth.init({
firstFactors: testContext.firstFactors,
})
);
}

SuperTokens.init({
usesDynamicLoginMethods: testContext.usesDynamicLoginMethods,
clientType: testContext.clientType,
Expand Down
9 changes: 7 additions & 2 deletions examples/for-tests/src/AppWithReactDomRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { AccessDeniedScreen } from "supertokens-auth-react/recipe/session/prebui
import { MultiFactorAuthPreBuiltUI } from "supertokens-auth-react/recipe/multifactorauth/prebuiltui";
import { TOTPPreBuiltUI } from "supertokens-auth-react/recipe/totp/prebuiltui";
import { BaseComponent, Home, Contact, Dashboard, DashboardNoAuthRequired } from "./App";
import { getEnabledRecipes } from "./testContext";
import { getEnabledRecipes, getTestContext } from "./testContext";

function AppWithReactDomRouter(props) {
/**
Expand All @@ -32,11 +32,12 @@ function AppWithReactDomRouter(props) {
const keyWithClaimValidators =
claimValidators !== undefined ? claimValidators.map((a) => a.id).join("_") : undefined;

const context = getTestContext();
const enabledRecipes = getEnabledRecipes();
const emailVerificationMode = window.localStorage.getItem("mode") || "OFF";
const websiteBasePath = window.localStorage.getItem("websiteBasePath") || undefined;

let recipePreBuiltUIList = [MultiFactorAuthPreBuiltUI, TOTPPreBuiltUI];
let recipePreBuiltUIList = [TOTPPreBuiltUI];
if (enabledRecipes.includes("emailpassword")) {
recipePreBuiltUIList.push(EmailPasswordPreBuiltUI);
}
Expand All @@ -56,6 +57,10 @@ function AppWithReactDomRouter(props) {
recipePreBuiltUIList.push(EmailVerificationPreBuiltUI);
}

if (context.enableMFA) {
recipePreBuiltUIList.push(MultiFactorAuthPreBuiltUI);
}

return (
<div className="App">
<Router>
Expand Down
1 change: 1 addition & 0 deletions examples/for-tests/src/testContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function getTestContext() {
signIn: localStorage.getItem("SIGNIN_SETTING_TYPE"),
signUp: localStorage.getItem("SIGNUP_SETTING_TYPE"),
},
enableMFA: localStorage.getItem("enableMFA") === "true",
};
return ret;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/build/emailverification-shared.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading