|
| 1 | +import type { Meta, StoryObj } from "@storybook/react"; |
| 2 | +import meta, { Args } from "./authPage.stories"; |
| 3 | + |
| 4 | +type Story = StoryObj<Args>; |
| 5 | + |
| 6 | +export default { |
| 7 | + ...meta, |
| 8 | + title: "WebAuthn/Auth", |
| 9 | +}; |
| 10 | + |
| 11 | +// Basic WebAuthn stories for sign up/sign in flows |
| 12 | +export const SignUpForm: Story = { |
| 13 | + args: { |
| 14 | + "multifactorauth.firstFactors": ["webauthn"], |
| 15 | + defaultToSignUp: true, |
| 16 | + }, |
| 17 | +}; |
| 18 | + |
| 19 | +export const SignInForm: Story = { |
| 20 | + args: { |
| 21 | + path: "/auth", |
| 22 | + "multifactorauth.firstFactors": ["webauthn"], |
| 23 | + defaultToSignUp: false, |
| 24 | + }, |
| 25 | +}; |
| 26 | + |
| 27 | +// Combined with other authentication methods |
| 28 | +export const CombinedWithEmailPassword: Story = { |
| 29 | + args: { |
| 30 | + "multifactorauth.firstFactors": ["emailpassword", "webauthn"], |
| 31 | + }, |
| 32 | +}; |
| 33 | + |
| 34 | +export const CombinedWithPasswordless: Story = { |
| 35 | + args: { |
| 36 | + "multifactorauth.firstFactors": ["otp-email", "webauthn"], |
| 37 | + }, |
| 38 | +}; |
| 39 | + |
| 40 | +export const CombinedWithThirdParty: Story = { |
| 41 | + args: { |
| 42 | + "multifactorauth.firstFactors": ["thirdparty", "webauthn"], |
| 43 | + }, |
| 44 | +}; |
| 45 | + |
| 46 | +export const AllAuthMethods: Story = { |
| 47 | + args: { |
| 48 | + "multifactorauth.firstFactors": ["emailpassword", "thirdparty", "otp-email", "otp-phone", "webauthn"], |
| 49 | + }, |
| 50 | +}; |
| 51 | + |
| 52 | +// Recovery scenarios |
| 53 | +export const SendRecoveryEmail: Story = { |
| 54 | + args: { |
| 55 | + path: "/auth/webauthn/recover/send-email", |
| 56 | + "multifactorauth.firstFactors": ["webauthn"], |
| 57 | + }, |
| 58 | +}; |
| 59 | + |
| 60 | +export const RecoveryEmailClicked: Story = { |
| 61 | + args: { |
| 62 | + path: "/auth/webauthn/recover", |
| 63 | + "multifactorauth.firstFactors": ["webauthn"], |
| 64 | + }, |
| 65 | + // loaders: [ |
| 66 | + // async () => ({ |
| 67 | + // funcOverrides: { |
| 68 | + // webauthn: (oI: any) => ({ |
| 69 | + // ...oI, |
| 70 | + // generateRecoverAccountToken: async () => ({ |
| 71 | + // status: "OK", |
| 72 | + // fetchResponse: undefined as any, |
| 73 | + // }), |
| 74 | + // }), |
| 75 | + // }, |
| 76 | + // }), |
| 77 | + // ], |
| 78 | +}; |
| 79 | + |
| 80 | +export const RecoverAccountTokenInvalid: Story = { |
| 81 | + args: { |
| 82 | + path: "/auth/webauthn/recover", |
| 83 | + query: "?token=invalid-token", |
| 84 | + "multifactorauth.firstFactors": ["webauthn"], |
| 85 | + }, |
| 86 | + loaders: [ |
| 87 | + async () => ({ |
| 88 | + funcOverrides: { |
| 89 | + webauthn: (oI: any) => ({ |
| 90 | + ...oI, |
| 91 | + getRegisterOptions: async () => ({ |
| 92 | + status: "RECOVER_ACCOUNT_TOKEN_INVALID_ERROR", |
| 93 | + fetchResponse: undefined as any, |
| 94 | + }), |
| 95 | + }), |
| 96 | + }, |
| 97 | + }), |
| 98 | + ], |
| 99 | +}; |
| 100 | + |
| 101 | +// Error scenarios |
| 102 | +export const WebAuthnNotSupported: Story = { |
| 103 | + args: { |
| 104 | + "multifactorauth.firstFactors": ["webauthn"], |
| 105 | + }, |
| 106 | + loaders: [ |
| 107 | + async () => ({ |
| 108 | + funcOverrides: { |
| 109 | + webauthn: (oI: any) => ({ |
| 110 | + ...oI, |
| 111 | + doesBrowserSupportWebAuthn: async () => ({ |
| 112 | + status: "OK", |
| 113 | + browserSupportsWebauthn: false, |
| 114 | + platformAuthenticatorIsAvailable: false, |
| 115 | + }), |
| 116 | + }), |
| 117 | + }, |
| 118 | + }), |
| 119 | + ], |
| 120 | +}; |
| 121 | + |
| 122 | +export const InvalidCredentials: Story = { |
| 123 | + args: { |
| 124 | + path: "/auth", |
| 125 | + "multifactorauth.firstFactors": ["webauthn"], |
| 126 | + defaultToSignUp: false, |
| 127 | + }, |
| 128 | + loaders: [ |
| 129 | + async () => ({ |
| 130 | + funcOverrides: { |
| 131 | + webauthn: (oI: any) => ({ |
| 132 | + ...oI, |
| 133 | + authenticateCredentialWithSignIn: async () => ({ |
| 134 | + status: "INVALID_CREDENTIALS_ERROR", |
| 135 | + fetchResponse: undefined as any, |
| 136 | + }), |
| 137 | + }), |
| 138 | + }, |
| 139 | + }), |
| 140 | + ], |
| 141 | +}; |
0 commit comments