@atproto/oauth-provider-ui 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.linguirc +57 -0
- package/CHANGELOG.md +7 -0
- package/CONTRIBUTING.md +6 -0
- package/LICENSE.txt +7 -0
- package/dist/assets/COdVzed-.css +3 -0
- package/dist/assets/COdVzed-.js +100 -0
- package/dist/assets/COdVzed-.js.map +1 -0
- package/dist/assets/Cqnfnbvc.js +6 -0
- package/dist/assets/Cqnfnbvc.js.map +1 -0
- package/dist/assets/bundle-manifest.json +630 -0
- package/dist/assets/error-view-Bu4y7Nd8.js +208 -0
- package/dist/assets/error-view-Bu4y7Nd8.js.map +1 -0
- package/dist/assets/index-DXlCRM6V.js +36 -0
- package/dist/assets/index-DXlCRM6V.js.map +1 -0
- package/dist/assets/messages-2GoTm2qL.js +4 -0
- package/dist/assets/messages-2GoTm2qL.js.map +1 -0
- package/dist/assets/messages-6Cn2Jbhw.js +4 -0
- package/dist/assets/messages-6Cn2Jbhw.js.map +1 -0
- package/dist/assets/messages-75hFgOK2.js +4 -0
- package/dist/assets/messages-75hFgOK2.js.map +1 -0
- package/dist/assets/messages-B3OK4k0O.js +4 -0
- package/dist/assets/messages-B3OK4k0O.js.map +1 -0
- package/dist/assets/messages-BNXlPzKV.js +4 -0
- package/dist/assets/messages-BNXlPzKV.js.map +1 -0
- package/dist/assets/messages-BUygB8mD.js +4 -0
- package/dist/assets/messages-BUygB8mD.js.map +1 -0
- package/dist/assets/messages-BVPPcwNr.js +4 -0
- package/dist/assets/messages-BVPPcwNr.js.map +1 -0
- package/dist/assets/messages-BbbWUQS8.js +4 -0
- package/dist/assets/messages-BbbWUQS8.js.map +1 -0
- package/dist/assets/messages-BibKCYyW.js +4 -0
- package/dist/assets/messages-BibKCYyW.js.map +1 -0
- package/dist/assets/messages-BlPrr9_7.js +4 -0
- package/dist/assets/messages-BlPrr9_7.js.map +1 -0
- package/dist/assets/messages-ByVCw40U.js +4 -0
- package/dist/assets/messages-ByVCw40U.js.map +1 -0
- package/dist/assets/messages-C5DU1neP.js +4 -0
- package/dist/assets/messages-C5DU1neP.js.map +1 -0
- package/dist/assets/messages-C6IgUtbX.js +4 -0
- package/dist/assets/messages-C6IgUtbX.js.map +1 -0
- package/dist/assets/messages-C92Zzt2o.js +4 -0
- package/dist/assets/messages-C92Zzt2o.js.map +1 -0
- package/dist/assets/messages-CGZqYT14.js +4 -0
- package/dist/assets/messages-CGZqYT14.js.map +1 -0
- package/dist/assets/messages-CGlsy4wt.js +4 -0
- package/dist/assets/messages-CGlsy4wt.js.map +1 -0
- package/dist/assets/messages-CPT1nd0u.js +4 -0
- package/dist/assets/messages-CPT1nd0u.js.map +1 -0
- package/dist/assets/messages-CTTdXyw_.js +4 -0
- package/dist/assets/messages-CTTdXyw_.js.map +1 -0
- package/dist/assets/messages-ChK_C_Pj.js +4 -0
- package/dist/assets/messages-ChK_C_Pj.js.map +1 -0
- package/dist/assets/messages-CjJbk7Uf.js +4 -0
- package/dist/assets/messages-CjJbk7Uf.js.map +1 -0
- package/dist/assets/messages-CoiLjLYO.js +4 -0
- package/dist/assets/messages-CoiLjLYO.js.map +1 -0
- package/dist/assets/messages-Cwx6B4Ti.js +4 -0
- package/dist/assets/messages-Cwx6B4Ti.js.map +1 -0
- package/dist/assets/messages-D0uXAp_H.js +4 -0
- package/dist/assets/messages-D0uXAp_H.js.map +1 -0
- package/dist/assets/messages-DG0_arU0.js +4 -0
- package/dist/assets/messages-DG0_arU0.js.map +1 -0
- package/dist/assets/messages-DOXFJh9K.js +4 -0
- package/dist/assets/messages-DOXFJh9K.js.map +1 -0
- package/dist/assets/messages-DPK7nOoC.js +4 -0
- package/dist/assets/messages-DPK7nOoC.js.map +1 -0
- package/dist/assets/messages-Duccgtu0.js +4 -0
- package/dist/assets/messages-Duccgtu0.js.map +1 -0
- package/dist/assets/messages-DxTqgsHq.js +4 -0
- package/dist/assets/messages-DxTqgsHq.js.map +1 -0
- package/dist/assets/messages-E5_lTg7A.js +4 -0
- package/dist/assets/messages-E5_lTg7A.js.map +1 -0
- package/dist/assets/messages-UhunAjh1.js +4 -0
- package/dist/assets/messages-UhunAjh1.js.map +1 -0
- package/dist/assets/messages-Xg_3YLGw.js +4 -0
- package/dist/assets/messages-Xg_3YLGw.js.map +1 -0
- package/dist/assets/messages-iliBQHY2.js +4 -0
- package/dist/assets/messages-iliBQHY2.js.map +1 -0
- package/dist/assets/messages-lRprpIl-.js +4 -0
- package/dist/assets/messages-lRprpIl-.js.map +1 -0
- package/dist/assets/messages-pbPHQbz1.js +4 -0
- package/dist/assets/messages-pbPHQbz1.js.map +1 -0
- package/dist/assets/messages-q-O7ZQGs.js +4 -0
- package/dist/assets/messages-q-O7ZQGs.js.map +1 -0
- package/dist/lib/index.d.ts +19 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +47 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/tsconfig.backend.tsbuildinfo +1 -0
- package/lib/index.ts +72 -0
- package/package.json +73 -0
- package/rollup.config.js +102 -0
- package/src/authorization-page.html +183 -0
- package/src/authorization-page.tsx +55 -0
- package/src/backend-data.ts +35 -0
- package/src/components/forms/button-toggle-visibility.tsx +43 -0
- package/src/components/forms/button.tsx +60 -0
- package/src/components/forms/fieldset.tsx +55 -0
- package/src/components/forms/form-card-async.tsx +103 -0
- package/src/components/forms/form-card.tsx +49 -0
- package/src/components/forms/input-checkbox.tsx +78 -0
- package/src/components/forms/input-container.tsx +107 -0
- package/src/components/forms/input-email-address.tsx +65 -0
- package/src/components/forms/input-new-password.tsx +62 -0
- package/src/components/forms/input-password.tsx +87 -0
- package/src/components/forms/input-text.tsx +82 -0
- package/src/components/forms/input-token.tsx +94 -0
- package/src/components/forms/wizard-card.tsx +116 -0
- package/src/components/layouts/layout-title-page.tsx +77 -0
- package/src/components/layouts/layout-welcome.tsx +73 -0
- package/src/components/utils/account-identifier.tsx +23 -0
- package/src/components/utils/account-image.tsx +33 -0
- package/src/components/utils/admonition.tsx +52 -0
- package/src/components/utils/client-name.tsx +45 -0
- package/src/components/utils/error-card.tsx +93 -0
- package/src/components/utils/error-message.tsx +88 -0
- package/src/components/utils/help-card.tsx +46 -0
- package/src/components/utils/icons.tsx +88 -0
- package/src/components/utils/link-anchor.tsx +28 -0
- package/src/components/utils/link-title.tsx +26 -0
- package/src/components/utils/multi-lang-string.tsx +56 -0
- package/src/components/utils/password-strength-label.tsx +37 -0
- package/src/components/utils/password-strength-meter.tsx +58 -0
- package/src/components/utils/url-viewer.tsx +73 -0
- package/src/cookies.ts +11 -0
- package/src/error-page.html +125 -0
- package/src/error-page.tsx +29 -0
- package/src/hooks/use-api.ts +182 -0
- package/src/hooks/use-async-action.ts +120 -0
- package/src/hooks/use-bound-dispatch.ts +5 -0
- package/src/hooks/use-browser-color-scheme.ts +31 -0
- package/src/hooks/use-csrf-token.ts +5 -0
- package/src/hooks/use-random-string.ts +37 -0
- package/src/hooks/use-stepper.ts +87 -0
- package/src/index.html +13 -0
- package/src/lib/api.ts +234 -0
- package/src/lib/backend-data.ts +6 -0
- package/src/lib/clsx.ts +6 -0
- package/src/lib/json-client.ts +97 -0
- package/src/lib/password.ts +98 -0
- package/src/lib/ref.ts +17 -0
- package/src/lib/util.ts +13 -0
- package/src/locales/an/messages.po +487 -0
- package/src/locales/ast/messages.po +487 -0
- package/src/locales/ca/messages.po +487 -0
- package/src/locales/da/messages.po +487 -0
- package/src/locales/de/messages.po +487 -0
- package/src/locales/el/messages.po +487 -0
- package/src/locales/en/messages.po +487 -0
- package/src/locales/en-GB/messages.po +487 -0
- package/src/locales/es/messages.po +487 -0
- package/src/locales/eu/messages.po +487 -0
- package/src/locales/fi/messages.po +487 -0
- package/src/locales/fr/messages.po +487 -0
- package/src/locales/ga/messages.po +487 -0
- package/src/locales/gl/messages.po +487 -0
- package/src/locales/hi/messages.po +487 -0
- package/src/locales/hu/messages.po +487 -0
- package/src/locales/ia/messages.po +487 -0
- package/src/locales/id/messages.po +487 -0
- package/src/locales/it/messages.po +487 -0
- package/src/locales/ja/messages.po +487 -0
- package/src/locales/km/messages.po +487 -0
- package/src/locales/ko/messages.po +487 -0
- package/src/locales/load.ts +8 -0
- package/src/locales/locale-context.ts +19 -0
- package/src/locales/locale-provider.tsx +112 -0
- package/src/locales/locale-selector.tsx +58 -0
- package/src/locales/locales.ts +168 -0
- package/src/locales/ne/messages.po +487 -0
- package/src/locales/nl/messages.po +487 -0
- package/src/locales/pl/messages.po +487 -0
- package/src/locales/pt-BR/messages.po +487 -0
- package/src/locales/ro/messages.po +487 -0
- package/src/locales/ru/messages.po +487 -0
- package/src/locales/sv/messages.po +487 -0
- package/src/locales/th/messages.po +487 -0
- package/src/locales/tr/messages.po +487 -0
- package/src/locales/uk/messages.po +487 -0
- package/src/locales/vi/messages.po +487 -0
- package/src/locales/zh-CN/messages.po +487 -0
- package/src/locales/zh-HK/messages.po +487 -0
- package/src/locales/zh-TW/messages.po +487 -0
- package/src/styles.css +33 -0
- package/src/views/authorize/accept/accept-form.tsx +150 -0
- package/src/views/authorize/accept/accept-view.tsx +70 -0
- package/src/views/authorize/authorize-view.tsx +183 -0
- package/src/views/authorize/reset-password/reset-password-confirm-form.tsx +88 -0
- package/src/views/authorize/reset-password/reset-password-request-form.tsx +80 -0
- package/src/views/authorize/reset-password/reset-password-view.tsx +127 -0
- package/src/views/authorize/sign-in/sign-in-form.tsx +242 -0
- package/src/views/authorize/sign-in/sign-in-picker.tsx +116 -0
- package/src/views/authorize/sign-in/sign-in-view.tsx +145 -0
- package/src/views/authorize/sign-up/sign-up-account-form.tsx +142 -0
- package/src/views/authorize/sign-up/sign-up-disclaimer.tsx +51 -0
- package/src/views/authorize/sign-up/sign-up-handle-form.tsx +287 -0
- package/src/views/authorize/sign-up/sign-up-hcaptcha-form.tsx +108 -0
- package/src/views/authorize/sign-up/sign-up-view.tsx +158 -0
- package/src/views/authorize/welcome/welcome-view.tsx +56 -0
- package/src/views/error/error-view.tsx +31 -0
- package/tailwind.config.js +31 -0
- package/tsconfig.backend.json +8 -0
- package/tsconfig.frontend.json +10 -0
- package/tsconfig.frontend.tsbuildinfo +1 -0
- package/tsconfig.json +8 -0
- package/tsconfig.tools.json +8 -0
- package/tsconfig.tools.tsbuildinfo +1 -0
- package/vite.config.mjs +16 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { Trans, useLingui } from '@lingui/react/macro'
|
|
2
|
+
import { JSX, ReactNode, useCallback, useEffect, useRef, useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
AsyncActionController,
|
|
5
|
+
FormCardAsync,
|
|
6
|
+
FormCardAsyncProps,
|
|
7
|
+
} from '../../../components/forms/form-card-async.tsx'
|
|
8
|
+
import { InputText } from '../../../components/forms/input-text.tsx'
|
|
9
|
+
import { Admonition } from '../../../components/utils/admonition.tsx'
|
|
10
|
+
import {
|
|
11
|
+
AtSymbolIcon,
|
|
12
|
+
CheckMarkIcon,
|
|
13
|
+
XMarkIcon,
|
|
14
|
+
} from '../../../components/utils/icons.tsx'
|
|
15
|
+
import { clsx } from '../../../lib/clsx.ts'
|
|
16
|
+
import { mergeRefs } from '../../../lib/ref.ts'
|
|
17
|
+
import { Override } from '../../../lib/util.ts'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Spec limit is 63, but in practice, we've limited it to 18 in our implementations.
|
|
21
|
+
*
|
|
22
|
+
* @see {@link https://atproto.com/specs/handle | ATProto Handle Spec}
|
|
23
|
+
*/
|
|
24
|
+
const MAX_LENGTH = 18
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Spec limit is 1, but in practice, we've targeted at least 3 characters in handles.
|
|
28
|
+
*
|
|
29
|
+
* @see {@link https://atproto.com/specs/handle | ATProto Handle Spec}
|
|
30
|
+
*/
|
|
31
|
+
const MIN_LENGTH = 3
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Spec limit is 253, but in practice, we've targeted 30 characters in handles.
|
|
35
|
+
*
|
|
36
|
+
* @see {@link https://atproto.com/specs/handle | ATProto Handle Spec}
|
|
37
|
+
*/
|
|
38
|
+
const MAX_FULL_LENGTH = 30
|
|
39
|
+
|
|
40
|
+
type ValidDomain = `.${string}`
|
|
41
|
+
const isValidDomain = (domain: string): domain is ValidDomain =>
|
|
42
|
+
// Ignore domains that are so long that they would make the handle smaller
|
|
43
|
+
// than MIN_LENGTH characters
|
|
44
|
+
MIN_LENGTH + domain.length <= MAX_FULL_LENGTH &&
|
|
45
|
+
// Basic validation here
|
|
46
|
+
domain.startsWith('.') &&
|
|
47
|
+
!domain.endsWith('.')
|
|
48
|
+
|
|
49
|
+
function useSegmentValidator(domain: ValidDomain) {
|
|
50
|
+
const minLen = MIN_LENGTH
|
|
51
|
+
const maxLen = Math.min(MAX_LENGTH, MAX_FULL_LENGTH - domain.length)
|
|
52
|
+
|
|
53
|
+
const validateSegment = useCallback(
|
|
54
|
+
(segment: string) => {
|
|
55
|
+
const validLength = segment.length >= minLen && segment.length <= maxLen
|
|
56
|
+
const validCharset = /^[a-z0-9][a-z0-9-]+[a-z0-9]$/g.test(segment)
|
|
57
|
+
|
|
58
|
+
return { validLength, validCharset, valid: validLength && validCharset }
|
|
59
|
+
},
|
|
60
|
+
[maxLen, minLen],
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
minLength: minLen,
|
|
65
|
+
maxLength: maxLen,
|
|
66
|
+
validateSegment,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type SignUpHandleFormProps = Override<
|
|
71
|
+
Omit<
|
|
72
|
+
FormCardAsyncProps,
|
|
73
|
+
'append' | 'onCancel' | 'cancelLabel' | 'onSubmit' | 'submitLabel'
|
|
74
|
+
>,
|
|
75
|
+
{
|
|
76
|
+
domains: string[]
|
|
77
|
+
|
|
78
|
+
onNext: (signal: AbortSignal) => void | PromiseLike<void>
|
|
79
|
+
nextLabel?: ReactNode
|
|
80
|
+
|
|
81
|
+
onPrev?: () => void
|
|
82
|
+
prevLabel?: ReactNode
|
|
83
|
+
|
|
84
|
+
handle?: string
|
|
85
|
+
onHandle?: (handle: string | undefined) => void
|
|
86
|
+
}
|
|
87
|
+
>
|
|
88
|
+
|
|
89
|
+
export function SignUpHandleForm({
|
|
90
|
+
domains: availableDomains,
|
|
91
|
+
|
|
92
|
+
onNext,
|
|
93
|
+
nextLabel,
|
|
94
|
+
|
|
95
|
+
onPrev,
|
|
96
|
+
prevLabel,
|
|
97
|
+
|
|
98
|
+
handle: handleInit,
|
|
99
|
+
onHandle,
|
|
100
|
+
|
|
101
|
+
// FormCardProps
|
|
102
|
+
invalid,
|
|
103
|
+
children,
|
|
104
|
+
ref,
|
|
105
|
+
...props
|
|
106
|
+
}: SignUpHandleFormProps) {
|
|
107
|
+
const { t } = useLingui()
|
|
108
|
+
const domains = availableDomains.filter(isValidDomain)
|
|
109
|
+
|
|
110
|
+
const formRef = useRef<AsyncActionController>(null)
|
|
111
|
+
|
|
112
|
+
const [domainIdx, setDomainIdx] = useState(() => {
|
|
113
|
+
const idx = domains.findIndex((d) => handleInit?.endsWith(d))
|
|
114
|
+
return idx === -1 ? 0 : idx
|
|
115
|
+
})
|
|
116
|
+
const [segment, setSegment] = useState(() => handleInit?.split('.')[0] || '')
|
|
117
|
+
|
|
118
|
+
// Automatically update the domain index when the list length changes
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
setDomainIdx((v) => Math.min(v, domains.length - 1))
|
|
121
|
+
}, [domains.length])
|
|
122
|
+
|
|
123
|
+
const domain: ValidDomain | null = domains[domainIdx] || domains[0] || null
|
|
124
|
+
|
|
125
|
+
const { minLength, maxLength, validateSegment } = useSegmentValidator(domain)
|
|
126
|
+
|
|
127
|
+
const validity = validateSegment(segment)
|
|
128
|
+
const handle = domain && validity.valid ? `${segment}${domain}` : undefined
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
// Whenever the user changes the handle, abort any pending form action
|
|
131
|
+
formRef.current?.reset()
|
|
132
|
+
onHandle?.(handle)
|
|
133
|
+
}, [onHandle, handle])
|
|
134
|
+
|
|
135
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
136
|
+
|
|
137
|
+
const preview = `@${segment}${domain}`
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<FormCardAsync
|
|
141
|
+
{...props}
|
|
142
|
+
ref={mergeRefs([ref, formRef])}
|
|
143
|
+
onCancel={onPrev}
|
|
144
|
+
cancelLabel={prevLabel}
|
|
145
|
+
onSubmit={onNext}
|
|
146
|
+
submitLabel={nextLabel}
|
|
147
|
+
invalid={invalid || !handle}
|
|
148
|
+
append={children}
|
|
149
|
+
>
|
|
150
|
+
<div>
|
|
151
|
+
<ValidationMessage hasValue={!!segment} valid={validity.validLength}>
|
|
152
|
+
<Trans>
|
|
153
|
+
Between {minLength} and {maxLength} characters
|
|
154
|
+
</Trans>
|
|
155
|
+
</ValidationMessage>
|
|
156
|
+
<ValidationMessage hasValue={!!segment} valid={validity.validCharset}>
|
|
157
|
+
<Trans>Only letters, numbers, and hyphens</Trans>
|
|
158
|
+
</ValidationMessage>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<InputText
|
|
162
|
+
ref={inputRef}
|
|
163
|
+
icon={<AtSymbolIcon className="w-5" />}
|
|
164
|
+
name="handle"
|
|
165
|
+
type="text"
|
|
166
|
+
title={t`Type your desired username`}
|
|
167
|
+
pattern="[a-z0-9][a-z0-9\-]+[a-z0-9]"
|
|
168
|
+
minLength={minLength}
|
|
169
|
+
maxLength={maxLength}
|
|
170
|
+
autoCapitalize="none"
|
|
171
|
+
autoCorrect="off"
|
|
172
|
+
autoComplete="off"
|
|
173
|
+
dir="auto"
|
|
174
|
+
enterKeyHint="done"
|
|
175
|
+
autoFocus
|
|
176
|
+
required
|
|
177
|
+
value={segment}
|
|
178
|
+
onChange={(event) => {
|
|
179
|
+
const segment = event.target.value.toLowerCase()
|
|
180
|
+
|
|
181
|
+
// Ensure the input is always lowercase
|
|
182
|
+
const selectionStart = event.target.selectionStart
|
|
183
|
+
const selectionEnd = event.target.selectionEnd
|
|
184
|
+
event.target.value = segment
|
|
185
|
+
event.target.setSelectionRange(selectionStart, selectionEnd)
|
|
186
|
+
|
|
187
|
+
setSegment(segment)
|
|
188
|
+
}}
|
|
189
|
+
append={
|
|
190
|
+
// @TODO refactor this to a separate component
|
|
191
|
+
domains.length > 1 && (
|
|
192
|
+
<select
|
|
193
|
+
onClick={(event) => event.stopPropagation()}
|
|
194
|
+
onMouseDown={(event) => event.stopPropagation()}
|
|
195
|
+
value={domainIdx}
|
|
196
|
+
aria-label={t`Select domain`}
|
|
197
|
+
onChange={(event) => {
|
|
198
|
+
setDomainIdx(Number(event.target.value))
|
|
199
|
+
inputRef.current?.focus()
|
|
200
|
+
}}
|
|
201
|
+
className={clsx(
|
|
202
|
+
'block w-full',
|
|
203
|
+
'text-sm',
|
|
204
|
+
'rounded-lg p-2',
|
|
205
|
+
'bg-white dark:bg-slate-600',
|
|
206
|
+
)}
|
|
207
|
+
>
|
|
208
|
+
{domains.map((domain, idx) => (
|
|
209
|
+
<option key={domain} value={idx}>
|
|
210
|
+
{domain}
|
|
211
|
+
</option>
|
|
212
|
+
))}
|
|
213
|
+
</select>
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
bellow={
|
|
217
|
+
<Trans>
|
|
218
|
+
Your full username will be:{' '}
|
|
219
|
+
{segment.length ? (
|
|
220
|
+
<strong className="text-gray-800 dark:text-gray-200">
|
|
221
|
+
{preview}
|
|
222
|
+
</strong>
|
|
223
|
+
) : (
|
|
224
|
+
<span
|
|
225
|
+
aria-hidden
|
|
226
|
+
className="bg-gray-300 dark:bg-slate-600 rounded-md p-2 w-24"
|
|
227
|
+
/>
|
|
228
|
+
)}
|
|
229
|
+
</Trans>
|
|
230
|
+
}
|
|
231
|
+
/>
|
|
232
|
+
|
|
233
|
+
<Admonition role="status">
|
|
234
|
+
<p className="text-md">
|
|
235
|
+
<Trans>
|
|
236
|
+
You can change this username to any domain name you control after
|
|
237
|
+
your account is set up.
|
|
238
|
+
</Trans>
|
|
239
|
+
</p>
|
|
240
|
+
</Admonition>
|
|
241
|
+
</FormCardAsync>
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
type ValidationMessageProps = JSX.IntrinsicElements['div'] & {
|
|
246
|
+
valid: boolean
|
|
247
|
+
hasValue: boolean
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function ValidationMessage({
|
|
251
|
+
valid,
|
|
252
|
+
hasValue,
|
|
253
|
+
|
|
254
|
+
// div
|
|
255
|
+
children,
|
|
256
|
+
className,
|
|
257
|
+
...props
|
|
258
|
+
}: ValidationMessageProps) {
|
|
259
|
+
const { t } = useLingui()
|
|
260
|
+
return (
|
|
261
|
+
<div
|
|
262
|
+
{...props}
|
|
263
|
+
className={clsx('flex flex-row items-center gap-2', className)}
|
|
264
|
+
>
|
|
265
|
+
{hasValue ? (
|
|
266
|
+
<>
|
|
267
|
+
{valid ? (
|
|
268
|
+
<CheckMarkIcon
|
|
269
|
+
className="inline-block w-4 h-4 text-success"
|
|
270
|
+
title={t`Valid`}
|
|
271
|
+
/>
|
|
272
|
+
) : (
|
|
273
|
+
<XMarkIcon
|
|
274
|
+
className="inline-block w-4 h-4 text-error"
|
|
275
|
+
title={t`Invalid`}
|
|
276
|
+
/>
|
|
277
|
+
)}
|
|
278
|
+
</>
|
|
279
|
+
) : (
|
|
280
|
+
<div aria-hidden className="w-4 h-4 flex items-center justify-center">
|
|
281
|
+
<div className="bg-gray-300 dark:bg-slate-600 rounded-full w-2 h-2" />
|
|
282
|
+
</div>
|
|
283
|
+
)}
|
|
284
|
+
<div className="text-sm">{children}</div>
|
|
285
|
+
</div>
|
|
286
|
+
)
|
|
287
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type HCaptcha from '@hcaptcha/react-hcaptcha'
|
|
2
|
+
import {
|
|
3
|
+
ForwardedRef,
|
|
4
|
+
ReactNode,
|
|
5
|
+
lazy,
|
|
6
|
+
useCallback,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from 'react'
|
|
10
|
+
import {
|
|
11
|
+
FormCardAsync,
|
|
12
|
+
FormCardAsyncProps,
|
|
13
|
+
} from '../../../components/forms/form-card-async.tsx'
|
|
14
|
+
import { useBrowserColorScheme } from '../../../hooks/use-browser-color-scheme.ts'
|
|
15
|
+
import { mergeRefs } from '../../../lib/ref.ts'
|
|
16
|
+
import { Override } from '../../../lib/util.ts'
|
|
17
|
+
|
|
18
|
+
export type SignUpHcaptchaFormProps = Override<
|
|
19
|
+
Omit<
|
|
20
|
+
FormCardAsyncProps,
|
|
21
|
+
'append' | 'onSubmit' | 'submitLabel' | 'onCancel' | 'cancelLabel'
|
|
22
|
+
>,
|
|
23
|
+
{
|
|
24
|
+
siteKey: string
|
|
25
|
+
|
|
26
|
+
token?: string
|
|
27
|
+
onToken: (token: string, ekey: string) => void
|
|
28
|
+
|
|
29
|
+
prevLabel?: ReactNode
|
|
30
|
+
onPrev?: () => void
|
|
31
|
+
|
|
32
|
+
nextLabel?: ReactNode
|
|
33
|
+
onNext: (signal: AbortSignal) => void | PromiseLike<void>
|
|
34
|
+
|
|
35
|
+
ref?: ForwardedRef<HCaptcha>
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
|
|
39
|
+
const HCaptchaLazy = lazy(() => import('@hcaptcha/react-hcaptcha'))
|
|
40
|
+
|
|
41
|
+
export function SignUpHcaptchaForm({
|
|
42
|
+
siteKey,
|
|
43
|
+
|
|
44
|
+
token: tokenInit,
|
|
45
|
+
onToken,
|
|
46
|
+
|
|
47
|
+
prevLabel,
|
|
48
|
+
onPrev,
|
|
49
|
+
|
|
50
|
+
nextLabel,
|
|
51
|
+
onNext,
|
|
52
|
+
|
|
53
|
+
ref,
|
|
54
|
+
|
|
55
|
+
// FormCardProps
|
|
56
|
+
invalid,
|
|
57
|
+
children,
|
|
58
|
+
...props
|
|
59
|
+
}: SignUpHcaptchaFormProps) {
|
|
60
|
+
const captchaRef = useRef<HCaptcha>(null)
|
|
61
|
+
const theme = useBrowserColorScheme()
|
|
62
|
+
const [token, setToken] = useState<string | undefined>(tokenInit)
|
|
63
|
+
|
|
64
|
+
const onLoad = useCallback(() => {
|
|
65
|
+
// this reaches out to the hCaptcha JS API and runs the
|
|
66
|
+
// execute function on it. you can use other functions as
|
|
67
|
+
// documented here:
|
|
68
|
+
// https://docs.hcaptcha.com/configuration#jsapi
|
|
69
|
+
captchaRef.current?.execute()
|
|
70
|
+
}, [])
|
|
71
|
+
|
|
72
|
+
const onVerify = useCallback(
|
|
73
|
+
(token: string, ekey: string) => {
|
|
74
|
+
setToken(token)
|
|
75
|
+
onToken(token, ekey)
|
|
76
|
+
},
|
|
77
|
+
[onToken],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
const doSubmit = useCallback(
|
|
81
|
+
(signal: AbortSignal) => {
|
|
82
|
+
if (token) return onNext(signal)
|
|
83
|
+
else if (captchaRef.current) captchaRef.current.execute()
|
|
84
|
+
else throw new Error('Unable to load hCaptcha')
|
|
85
|
+
},
|
|
86
|
+
[token, onNext],
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<FormCardAsync
|
|
91
|
+
{...props}
|
|
92
|
+
cancelLabel={prevLabel}
|
|
93
|
+
onCancel={onPrev}
|
|
94
|
+
submitLabel={nextLabel}
|
|
95
|
+
onSubmit={doSubmit}
|
|
96
|
+
append={children}
|
|
97
|
+
invalid={invalid || !token}
|
|
98
|
+
>
|
|
99
|
+
<HCaptchaLazy
|
|
100
|
+
theme={theme}
|
|
101
|
+
sitekey={siteKey}
|
|
102
|
+
onLoad={onLoad}
|
|
103
|
+
onVerify={onVerify}
|
|
104
|
+
ref={mergeRefs([ref, captchaRef])}
|
|
105
|
+
/>
|
|
106
|
+
</FormCardAsync>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Trans, useLingui } from '@lingui/react/macro'
|
|
2
|
+
import { useCallback, useState } from 'react'
|
|
3
|
+
import type { CustomizationData } from '@atproto/oauth-provider-api'
|
|
4
|
+
import { WizardCard } from '../../../components/forms/wizard-card.tsx'
|
|
5
|
+
import {
|
|
6
|
+
LayoutTitlePage,
|
|
7
|
+
LayoutTitlePageProps,
|
|
8
|
+
} from '../../../components/layouts/layout-title-page.tsx'
|
|
9
|
+
import { HelpCard } from '../../../components/utils/help-card.tsx'
|
|
10
|
+
import { Override } from '../../../lib/util.ts'
|
|
11
|
+
import {
|
|
12
|
+
SignUpAccountForm,
|
|
13
|
+
SignUpAccountFormOutput,
|
|
14
|
+
} from './sign-up-account-form.tsx'
|
|
15
|
+
import { SignUpDisclaimer } from './sign-up-disclaimer.tsx'
|
|
16
|
+
import { SignUpHandleForm } from './sign-up-handle-form.tsx'
|
|
17
|
+
import { SignUpHcaptchaForm } from './sign-up-hcaptcha-form.tsx'
|
|
18
|
+
|
|
19
|
+
export type SignUpViewProps = Override<
|
|
20
|
+
LayoutTitlePageProps,
|
|
21
|
+
{
|
|
22
|
+
customizationData?: CustomizationData
|
|
23
|
+
|
|
24
|
+
onBack?: () => void
|
|
25
|
+
onValidateNewHandle: (
|
|
26
|
+
data: { handle: string },
|
|
27
|
+
signal?: AbortSignal,
|
|
28
|
+
) => void | PromiseLike<void>
|
|
29
|
+
onDone: (
|
|
30
|
+
data: SignUpAccountFormOutput & {
|
|
31
|
+
handle: string
|
|
32
|
+
hcaptchaToken?: string
|
|
33
|
+
},
|
|
34
|
+
signal?: AbortSignal,
|
|
35
|
+
) => void | PromiseLike<void>
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
|
|
39
|
+
export function SignUpView({
|
|
40
|
+
customizationData: {
|
|
41
|
+
availableUserDomains = [],
|
|
42
|
+
hcaptchaSiteKey = undefined,
|
|
43
|
+
inviteCodeRequired = true,
|
|
44
|
+
links,
|
|
45
|
+
} = {},
|
|
46
|
+
|
|
47
|
+
onValidateNewHandle,
|
|
48
|
+
onDone,
|
|
49
|
+
onBack,
|
|
50
|
+
|
|
51
|
+
// LayoutTitlePage
|
|
52
|
+
...props
|
|
53
|
+
}: SignUpViewProps) {
|
|
54
|
+
const { t } = useLingui()
|
|
55
|
+
const [credentials, setCredentials] = useState<
|
|
56
|
+
undefined | SignUpAccountFormOutput
|
|
57
|
+
>(undefined)
|
|
58
|
+
const [handle, setHandle] = useState<undefined | string>(undefined)
|
|
59
|
+
const [hcaptcha, setHcaptcha] = useState<undefined | string>(undefined)
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* "false" indicates that the hcaptcha token is invalid (required but not provided)
|
|
63
|
+
*/
|
|
64
|
+
const hcaptchaToken = hcaptchaSiteKey == null ? undefined : hcaptcha || false
|
|
65
|
+
|
|
66
|
+
const doDone = useCallback(
|
|
67
|
+
(signal: AbortSignal) => {
|
|
68
|
+
if (credentials && handle && hcaptchaToken !== false) {
|
|
69
|
+
return onDone({ ...credentials, handle, hcaptchaToken }, signal)
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
[credentials, handle, hcaptchaToken, onDone],
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<LayoutTitlePage
|
|
77
|
+
{...props}
|
|
78
|
+
title={props.title ?? t`Create Account`}
|
|
79
|
+
subtitle={
|
|
80
|
+
props.subtitle ?? <Trans>We're so excited to have you join us!</Trans>
|
|
81
|
+
}
|
|
82
|
+
>
|
|
83
|
+
<WizardCard
|
|
84
|
+
doneLabel={<Trans>Sign up</Trans>}
|
|
85
|
+
onBack={onBack}
|
|
86
|
+
onDone={doDone}
|
|
87
|
+
steps={[
|
|
88
|
+
// We use the handle input first since the "onValidateNewHandle" check
|
|
89
|
+
// will make it less likely that the actual signup call will fail, and
|
|
90
|
+
// will result in a better user experience, especially if there is an
|
|
91
|
+
// issue with the email address (e.g. already in use).
|
|
92
|
+
{
|
|
93
|
+
invalid: !handle,
|
|
94
|
+
titleRender: () => <Trans>Choose a username</Trans>,
|
|
95
|
+
contentRender: ({ prev, prevLabel, next, nextLabel, invalid }) => (
|
|
96
|
+
<SignUpHandleForm
|
|
97
|
+
className="flex-grow"
|
|
98
|
+
invalid={invalid}
|
|
99
|
+
domains={availableUserDomains}
|
|
100
|
+
handle={handle}
|
|
101
|
+
onHandle={setHandle}
|
|
102
|
+
prevLabel={prevLabel}
|
|
103
|
+
onPrev={prev}
|
|
104
|
+
nextLabel={nextLabel}
|
|
105
|
+
onNext={async (signal) => {
|
|
106
|
+
if (handle) await onValidateNewHandle({ handle }, signal)
|
|
107
|
+
if (!signal.aborted) return next(signal)
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<SignUpDisclaimer links={links} />
|
|
111
|
+
</SignUpHandleForm>
|
|
112
|
+
),
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
invalid: !credentials,
|
|
116
|
+
titleRender: () => <Trans>Your account</Trans>,
|
|
117
|
+
contentRender: ({ prev, prevLabel, next, nextLabel, invalid }) => (
|
|
118
|
+
<SignUpAccountForm
|
|
119
|
+
className="flex-grow"
|
|
120
|
+
invalid={invalid}
|
|
121
|
+
prevLabel={prevLabel}
|
|
122
|
+
onPrev={prev}
|
|
123
|
+
nextLabel={nextLabel}
|
|
124
|
+
onNext={next}
|
|
125
|
+
inviteCodeRequired={inviteCodeRequired}
|
|
126
|
+
credentials={credentials}
|
|
127
|
+
onCredentials={setCredentials}
|
|
128
|
+
>
|
|
129
|
+
<SignUpDisclaimer links={links} />
|
|
130
|
+
</SignUpAccountForm>
|
|
131
|
+
),
|
|
132
|
+
},
|
|
133
|
+
hcaptchaSiteKey != null && {
|
|
134
|
+
invalid: hcaptchaToken === false,
|
|
135
|
+
titleRender: () => <Trans>Verify you are human</Trans>,
|
|
136
|
+
contentRender: ({ prev, prevLabel, next, nextLabel, invalid }) => (
|
|
137
|
+
<SignUpHcaptchaForm
|
|
138
|
+
className="flex-grow"
|
|
139
|
+
invalid={invalid}
|
|
140
|
+
siteKey={hcaptchaSiteKey}
|
|
141
|
+
token={hcaptcha}
|
|
142
|
+
onToken={setHcaptcha}
|
|
143
|
+
prevLabel={prevLabel}
|
|
144
|
+
onPrev={prev}
|
|
145
|
+
nextLabel={nextLabel}
|
|
146
|
+
onNext={next}
|
|
147
|
+
>
|
|
148
|
+
<SignUpDisclaimer links={links} />
|
|
149
|
+
</SignUpHcaptchaForm>
|
|
150
|
+
),
|
|
151
|
+
},
|
|
152
|
+
]}
|
|
153
|
+
/>
|
|
154
|
+
|
|
155
|
+
<HelpCard className="mt-4" links={links} />
|
|
156
|
+
</LayoutTitlePage>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Trans, useLingui } from '@lingui/react/macro'
|
|
2
|
+
import { Button } from '../../../components/forms/button.tsx'
|
|
3
|
+
import {
|
|
4
|
+
LayoutWelcome,
|
|
5
|
+
LayoutWelcomeProps,
|
|
6
|
+
} from '../../../components/layouts/layout-welcome.tsx'
|
|
7
|
+
import { Override } from '../../../lib/util.ts'
|
|
8
|
+
|
|
9
|
+
export type WelcomeViewParams = Override<
|
|
10
|
+
LayoutWelcomeProps,
|
|
11
|
+
{
|
|
12
|
+
onSignIn?: () => void
|
|
13
|
+
onSignUp?: () => void
|
|
14
|
+
onCancel?: () => void
|
|
15
|
+
}
|
|
16
|
+
>
|
|
17
|
+
|
|
18
|
+
export function WelcomeView({
|
|
19
|
+
onSignUp,
|
|
20
|
+
onSignIn,
|
|
21
|
+
onCancel,
|
|
22
|
+
|
|
23
|
+
// LayoutWelcome
|
|
24
|
+
...props
|
|
25
|
+
}: WelcomeViewParams) {
|
|
26
|
+
const { t } = useLingui()
|
|
27
|
+
return (
|
|
28
|
+
<LayoutWelcome {...props} title={props.title ?? t`Authenticate`}>
|
|
29
|
+
{onSignUp && (
|
|
30
|
+
<Button
|
|
31
|
+
className={'m-1 w-60 max-w-full min-w-min'}
|
|
32
|
+
color={onSignIn ? 'brand' : undefined}
|
|
33
|
+
onClick={onSignUp}
|
|
34
|
+
>
|
|
35
|
+
<Trans>Create a new account</Trans>
|
|
36
|
+
</Button>
|
|
37
|
+
)}
|
|
38
|
+
|
|
39
|
+
{onSignIn && (
|
|
40
|
+
<Button
|
|
41
|
+
className={'m-1 w-60 max-w-full min-w-min'}
|
|
42
|
+
color={onSignUp ? undefined : 'brand'}
|
|
43
|
+
onClick={onSignIn}
|
|
44
|
+
>
|
|
45
|
+
<Trans>Sign in</Trans>
|
|
46
|
+
</Button>
|
|
47
|
+
)}
|
|
48
|
+
|
|
49
|
+
{onCancel && (
|
|
50
|
+
<Button className="m-1 w-60 max-w-full min-w-min" onClick={onCancel}>
|
|
51
|
+
<Trans>Cancel</Trans>
|
|
52
|
+
</Button>
|
|
53
|
+
)}
|
|
54
|
+
</LayoutWelcome>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useLingui } from '@lingui/react/macro'
|
|
2
|
+
import { memo } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
LayoutWelcome,
|
|
5
|
+
LayoutWelcomeProps,
|
|
6
|
+
} from '../../components/layouts/layout-welcome.tsx'
|
|
7
|
+
import { ErrorCard } from '../../components/utils/error-card.tsx'
|
|
8
|
+
import { Override } from '../../lib/util.ts'
|
|
9
|
+
|
|
10
|
+
export type ErrorViewProps = Override<
|
|
11
|
+
LayoutWelcomeProps,
|
|
12
|
+
{
|
|
13
|
+
error: unknown
|
|
14
|
+
}
|
|
15
|
+
>
|
|
16
|
+
|
|
17
|
+
export const ErrorView = memo(function ErrorView({
|
|
18
|
+
error,
|
|
19
|
+
|
|
20
|
+
// LayoutWelcome
|
|
21
|
+
title,
|
|
22
|
+
...props
|
|
23
|
+
}: ErrorViewProps) {
|
|
24
|
+
const { t } = useLingui()
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<LayoutWelcome {...props} title={title ?? t`Error`}>
|
|
28
|
+
<ErrorCard error={error} />
|
|
29
|
+
</LayoutWelcome>
|
|
30
|
+
)
|
|
31
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** @type {import('tailwindcss').Config} */
|
|
2
|
+
export default {
|
|
3
|
+
content: ['src/**/*.{js,ts,jsx,tsx}'],
|
|
4
|
+
theme: {
|
|
5
|
+
fontFamily: {
|
|
6
|
+
sans: [
|
|
7
|
+
'-apple-system',
|
|
8
|
+
'BlinkMacSystemFont',
|
|
9
|
+
'"Segoe UI"',
|
|
10
|
+
'Roboto',
|
|
11
|
+
'Helvetica',
|
|
12
|
+
'Arial',
|
|
13
|
+
'sans-serif',
|
|
14
|
+
],
|
|
15
|
+
mono: ['Monaco', 'mono'],
|
|
16
|
+
},
|
|
17
|
+
extend: {
|
|
18
|
+
colors: {
|
|
19
|
+
brand: 'rgb(var(--color-brand) / <alpha-value>)',
|
|
20
|
+
'brand-c': 'rgb(var(--color-brand-c) / <alpha-value>)',
|
|
21
|
+
error: 'rgb(var(--color-error) / <alpha-value>)',
|
|
22
|
+
'error-c': 'rgb(var(--color-error-c) / <alpha-value>)',
|
|
23
|
+
warning: 'rgb(var(--color-warning) / <alpha-value>)',
|
|
24
|
+
'warning-c': 'rgb(var(--color-warning-c) / <alpha-value>)',
|
|
25
|
+
success: 'rgb(var(--color-success) / <alpha-value>)',
|
|
26
|
+
'success-c': 'rgb(var(--color-success-c) / <alpha-value>)',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
plugins: [],
|
|
31
|
+
}
|