@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,242 @@
|
|
|
1
|
+
import { Trans, useLingui } from '@lingui/react/macro'
|
|
2
|
+
import { useCallback, useRef, useState } from 'react'
|
|
3
|
+
import { Button } from '../../../components/forms/button.tsx'
|
|
4
|
+
import { Fieldset } from '../../../components/forms/fieldset.tsx'
|
|
5
|
+
import {
|
|
6
|
+
FormCardAsync,
|
|
7
|
+
FormCardAsyncProps,
|
|
8
|
+
} from '../../../components/forms/form-card-async.tsx'
|
|
9
|
+
import { InputCheckbox } from '../../../components/forms/input-checkbox.tsx'
|
|
10
|
+
import { InputPassword } from '../../../components/forms/input-password.tsx'
|
|
11
|
+
import { InputText } from '../../../components/forms/input-text.tsx'
|
|
12
|
+
import { InputToken } from '../../../components/forms/input-token.tsx'
|
|
13
|
+
import { Admonition } from '../../../components/utils/admonition.tsx'
|
|
14
|
+
import { AtSymbolIcon } from '../../../components/utils/icons.tsx'
|
|
15
|
+
import { AsyncActionController } from '../../../hooks/use-async-action.ts'
|
|
16
|
+
import {
|
|
17
|
+
InvalidCredentialsError,
|
|
18
|
+
SecondAuthenticationFactorRequiredError,
|
|
19
|
+
} from '../../../lib/api.ts'
|
|
20
|
+
import { mergeRefs } from '../../../lib/ref.ts'
|
|
21
|
+
import { Override } from '../../../lib/util.ts'
|
|
22
|
+
|
|
23
|
+
export type SignInFormOutput = {
|
|
24
|
+
username: string
|
|
25
|
+
password: string
|
|
26
|
+
remember?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type SignInFormProps = Override<
|
|
30
|
+
Omit<FormCardAsyncProps, 'append' | 'onCancel'>,
|
|
31
|
+
{
|
|
32
|
+
usernameDefault?: string
|
|
33
|
+
usernameReadonly?: boolean
|
|
34
|
+
rememberDefault?: boolean
|
|
35
|
+
|
|
36
|
+
onBack?: () => void
|
|
37
|
+
onForgotPassword?: (emailHint?: string) => void
|
|
38
|
+
onSubmit: (
|
|
39
|
+
credentials: SignInFormOutput,
|
|
40
|
+
signal: AbortSignal,
|
|
41
|
+
) => void | PromiseLike<void>
|
|
42
|
+
}
|
|
43
|
+
>
|
|
44
|
+
|
|
45
|
+
export function SignInForm({
|
|
46
|
+
usernameDefault = '',
|
|
47
|
+
usernameReadonly = false,
|
|
48
|
+
rememberDefault = false,
|
|
49
|
+
|
|
50
|
+
onSubmit,
|
|
51
|
+
onBack,
|
|
52
|
+
onForgotPassword,
|
|
53
|
+
|
|
54
|
+
// FormCardAsync
|
|
55
|
+
ref,
|
|
56
|
+
invalid,
|
|
57
|
+
children,
|
|
58
|
+
...props
|
|
59
|
+
}: SignInFormProps) {
|
|
60
|
+
const { t } = useLingui()
|
|
61
|
+
|
|
62
|
+
const [username, setUsername] = useState<string>(usernameDefault)
|
|
63
|
+
const [password, setPassword] = useState<string>('')
|
|
64
|
+
const [remember, setRemember] = useState<boolean>(rememberDefault)
|
|
65
|
+
const [otp, setOtp] = useState<string | null>(null)
|
|
66
|
+
|
|
67
|
+
const [secondFactor, setSecondFactor] =
|
|
68
|
+
useState<null | SecondAuthenticationFactorRequiredError>(null)
|
|
69
|
+
|
|
70
|
+
const [loading, setLoading] = useState(false)
|
|
71
|
+
|
|
72
|
+
const formRef = useRef<AsyncActionController>(null)
|
|
73
|
+
|
|
74
|
+
const clearSecondFactor = useCallback(() => {
|
|
75
|
+
setOtp(null)
|
|
76
|
+
setSecondFactor(null)
|
|
77
|
+
}, [setOtp, setSecondFactor])
|
|
78
|
+
|
|
79
|
+
const resetState = useCallback(() => {
|
|
80
|
+
clearSecondFactor()
|
|
81
|
+
formRef.current?.reset()
|
|
82
|
+
}, [clearSecondFactor, formRef])
|
|
83
|
+
|
|
84
|
+
const doSubmit = useCallback(
|
|
85
|
+
async (signal: AbortSignal) => {
|
|
86
|
+
try {
|
|
87
|
+
await onSubmit(
|
|
88
|
+
{
|
|
89
|
+
username,
|
|
90
|
+
password,
|
|
91
|
+
remember,
|
|
92
|
+
...(secondFactor ? { [secondFactor.type]: otp } : {}),
|
|
93
|
+
},
|
|
94
|
+
signal,
|
|
95
|
+
)
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (signal.aborted) {
|
|
98
|
+
// If the action was aborted, ignore the error
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (err instanceof SecondAuthenticationFactorRequiredError) {
|
|
103
|
+
setSecondFactor(err)
|
|
104
|
+
|
|
105
|
+
// Do not re-throw 2FA required error to prevent the form from from
|
|
106
|
+
// displaying it. Instead, we handle the error by showing the second
|
|
107
|
+
// factor form.
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (err instanceof InvalidCredentialsError) {
|
|
112
|
+
// If the username/password are not valid, clear the second factor
|
|
113
|
+
// as valid credentials are a pre-requisite for 2FA.
|
|
114
|
+
clearSecondFactor()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Any thrown err will be displayed through the form's errorRender
|
|
118
|
+
throw err
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
[username, password, remember, secondFactor, otp, onSubmit],
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<FormCardAsync
|
|
126
|
+
{...props}
|
|
127
|
+
ref={mergeRefs([ref, formRef])}
|
|
128
|
+
onLoading={setLoading}
|
|
129
|
+
onCancel={onBack}
|
|
130
|
+
cancelLabel={t`Back`}
|
|
131
|
+
append={children}
|
|
132
|
+
invalid={
|
|
133
|
+
invalid || !username || !password || (secondFactor != null && !otp)
|
|
134
|
+
}
|
|
135
|
+
submitLabel={secondFactor ? t`Confirm` : t`Sign in`}
|
|
136
|
+
onSubmit={doSubmit}
|
|
137
|
+
>
|
|
138
|
+
<Fieldset disabled={loading} label={<Trans>Account</Trans>}>
|
|
139
|
+
<InputText
|
|
140
|
+
icon={<AtSymbolIcon className="w-5" />}
|
|
141
|
+
name="username"
|
|
142
|
+
type="text"
|
|
143
|
+
title={t`Username or email address`}
|
|
144
|
+
autoCapitalize="none"
|
|
145
|
+
autoCorrect="off"
|
|
146
|
+
autoComplete="username"
|
|
147
|
+
spellCheck="false"
|
|
148
|
+
dir="auto"
|
|
149
|
+
enterKeyHint="next"
|
|
150
|
+
required
|
|
151
|
+
readOnly={usernameReadonly}
|
|
152
|
+
disabled={usernameReadonly}
|
|
153
|
+
autoFocus
|
|
154
|
+
value={username}
|
|
155
|
+
onChange={(event) => {
|
|
156
|
+
resetState()
|
|
157
|
+
setUsername(event.target.value)
|
|
158
|
+
}}
|
|
159
|
+
/>
|
|
160
|
+
</Fieldset>
|
|
161
|
+
|
|
162
|
+
<InputPassword
|
|
163
|
+
name="password"
|
|
164
|
+
onChange={(event) => {
|
|
165
|
+
resetState()
|
|
166
|
+
setPassword(event.target.value)
|
|
167
|
+
}}
|
|
168
|
+
append={
|
|
169
|
+
onForgotPassword && (
|
|
170
|
+
<Button
|
|
171
|
+
className="text-sm"
|
|
172
|
+
type="button"
|
|
173
|
+
onClick={() => {
|
|
174
|
+
onForgotPassword(username?.includes('@') ? username : undefined)
|
|
175
|
+
}}
|
|
176
|
+
aria-label={t`Reset your password`}
|
|
177
|
+
>
|
|
178
|
+
<Trans>Forgot?</Trans>
|
|
179
|
+
</Button>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
enterKeyHint={secondFactor ? 'next' : 'done'}
|
|
183
|
+
disabled={loading}
|
|
184
|
+
required
|
|
185
|
+
/>
|
|
186
|
+
|
|
187
|
+
<Admonition role="status">
|
|
188
|
+
<p className="font-bold text-md text-brand pb-1">
|
|
189
|
+
<Trans>Warning</Trans>
|
|
190
|
+
</p>
|
|
191
|
+
<p className="text-sm">
|
|
192
|
+
<Trans>
|
|
193
|
+
Please verify the domain name of the website before entering your
|
|
194
|
+
password. Never enter your password on a domain you do not trust.
|
|
195
|
+
</Trans>
|
|
196
|
+
</p>
|
|
197
|
+
</Admonition>
|
|
198
|
+
|
|
199
|
+
<Fieldset
|
|
200
|
+
key="remember"
|
|
201
|
+
disabled={loading}
|
|
202
|
+
label={<Trans>Session</Trans>}
|
|
203
|
+
>
|
|
204
|
+
<InputCheckbox
|
|
205
|
+
name="remember"
|
|
206
|
+
title={t`Remember this account on this device`}
|
|
207
|
+
enterKeyHint={secondFactor ? 'next' : 'done'}
|
|
208
|
+
checked={remember}
|
|
209
|
+
onChange={(event) => setRemember(event.target.checked)}
|
|
210
|
+
>
|
|
211
|
+
<Trans>Remember this account on this device</Trans>
|
|
212
|
+
</InputCheckbox>
|
|
213
|
+
</Fieldset>
|
|
214
|
+
|
|
215
|
+
{secondFactor && (
|
|
216
|
+
<Fieldset
|
|
217
|
+
key="2fa"
|
|
218
|
+
disabled={loading}
|
|
219
|
+
label={<Trans>2FA Confirmation</Trans>}
|
|
220
|
+
>
|
|
221
|
+
<div>
|
|
222
|
+
<InputToken
|
|
223
|
+
title={t`Confirmation code`}
|
|
224
|
+
enterKeyHint="done"
|
|
225
|
+
required
|
|
226
|
+
autoFocus={true}
|
|
227
|
+
value={otp ?? ''}
|
|
228
|
+
onToken={setOtp}
|
|
229
|
+
/>
|
|
230
|
+
|
|
231
|
+
<p className="text-slate-600 dark:text-slate-400 text-sm">
|
|
232
|
+
<Trans>
|
|
233
|
+
Check your {secondFactor.hint} email for a login code and enter
|
|
234
|
+
it here.
|
|
235
|
+
</Trans>
|
|
236
|
+
</p>
|
|
237
|
+
</div>
|
|
238
|
+
</Fieldset>
|
|
239
|
+
)}
|
|
240
|
+
</FormCardAsync>
|
|
241
|
+
)
|
|
242
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { Trans, useLingui } from '@lingui/react/macro'
|
|
2
|
+
import type { Account } from '@atproto/oauth-provider-api'
|
|
3
|
+
import { Button } from '../../../components/forms/button.tsx'
|
|
4
|
+
import {
|
|
5
|
+
FormCard,
|
|
6
|
+
FormCardProps,
|
|
7
|
+
} from '../../../components/forms/form-card.tsx'
|
|
8
|
+
import { InputContainer } from '../../../components/forms/input-container.tsx'
|
|
9
|
+
import { AccountImage } from '../../../components/utils/account-image.tsx'
|
|
10
|
+
import {
|
|
11
|
+
AtSymbolIcon,
|
|
12
|
+
CaretRightIcon,
|
|
13
|
+
} from '../../../components/utils/icons.tsx'
|
|
14
|
+
import { Override } from '../../../lib/util.ts'
|
|
15
|
+
|
|
16
|
+
export type SignInPickerProps = Override<
|
|
17
|
+
Omit<FormCardProps, 'cancel' | 'actions' | 'append'>,
|
|
18
|
+
{
|
|
19
|
+
accounts: readonly Account[]
|
|
20
|
+
|
|
21
|
+
onAccount: (account: Account) => void
|
|
22
|
+
onOther?: () => void
|
|
23
|
+
onBack?: () => void
|
|
24
|
+
}
|
|
25
|
+
>
|
|
26
|
+
|
|
27
|
+
export function SignInPicker({
|
|
28
|
+
accounts,
|
|
29
|
+
|
|
30
|
+
onAccount,
|
|
31
|
+
onOther = undefined,
|
|
32
|
+
onBack,
|
|
33
|
+
|
|
34
|
+
// FormCard
|
|
35
|
+
children,
|
|
36
|
+
...props
|
|
37
|
+
}: SignInPickerProps) {
|
|
38
|
+
const { t } = useLingui()
|
|
39
|
+
return (
|
|
40
|
+
<FormCard
|
|
41
|
+
{...props}
|
|
42
|
+
append={children}
|
|
43
|
+
actions={null}
|
|
44
|
+
cancel={
|
|
45
|
+
onBack && (
|
|
46
|
+
<Button onClick={onBack}>
|
|
47
|
+
<Trans>Back</Trans>
|
|
48
|
+
</Button>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
>
|
|
52
|
+
<p className="text-slate-600 dark:text-slate-400 text-sm font-medium">
|
|
53
|
+
<Trans>Sign in as...</Trans>
|
|
54
|
+
</p>
|
|
55
|
+
|
|
56
|
+
{accounts.map((account) => {
|
|
57
|
+
const [name, identifier] = [
|
|
58
|
+
account.name,
|
|
59
|
+
account.preferred_username,
|
|
60
|
+
account.email,
|
|
61
|
+
account.sub,
|
|
62
|
+
].filter(Boolean) as [string, string?]
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<InputContainer
|
|
66
|
+
tabIndex={0}
|
|
67
|
+
key={account.sub}
|
|
68
|
+
onKeyDown={(event) => {
|
|
69
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
70
|
+
onAccount(account)
|
|
71
|
+
}
|
|
72
|
+
}}
|
|
73
|
+
onClick={() => onAccount(account)}
|
|
74
|
+
role="button"
|
|
75
|
+
aria-label={t`Sign in as ${account.name}`}
|
|
76
|
+
icon={<AccountImage src={account.picture} alt={name} />}
|
|
77
|
+
append={<CaretRightIcon aria-hidden className="h-4" />}
|
|
78
|
+
>
|
|
79
|
+
<span className="flex flex-wrap items-center">
|
|
80
|
+
<span className="font-medium truncate mr-2" arial-label={t`Name`}>
|
|
81
|
+
{name}
|
|
82
|
+
</span>
|
|
83
|
+
{identifier && (
|
|
84
|
+
<span
|
|
85
|
+
className="text-sm text-neutral-500 dark:text-neutral-400 truncate"
|
|
86
|
+
arial-label={t`Identifier`}
|
|
87
|
+
>
|
|
88
|
+
{identifier}
|
|
89
|
+
</span>
|
|
90
|
+
)}
|
|
91
|
+
</span>
|
|
92
|
+
</InputContainer>
|
|
93
|
+
)
|
|
94
|
+
})}
|
|
95
|
+
|
|
96
|
+
{onOther && (
|
|
97
|
+
<InputContainer
|
|
98
|
+
key="other"
|
|
99
|
+
tabIndex={0}
|
|
100
|
+
onKeyDown={(event) => {
|
|
101
|
+
if (event.key === 'Enter' || event.key === ' ') onOther()
|
|
102
|
+
}}
|
|
103
|
+
onClick={onOther}
|
|
104
|
+
aria-label={t`Login to account that is not listed`}
|
|
105
|
+
role="button"
|
|
106
|
+
append={<CaretRightIcon aria-hidden className="h-4" />}
|
|
107
|
+
icon={<AtSymbolIcon aria-hidden className="h-4" />}
|
|
108
|
+
>
|
|
109
|
+
<span className="truncate text-slate-700 dark:text-slate-400">
|
|
110
|
+
<Trans>Another account</Trans>
|
|
111
|
+
</span>
|
|
112
|
+
</InputContainer>
|
|
113
|
+
)}
|
|
114
|
+
</FormCard>
|
|
115
|
+
)
|
|
116
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Trans, useLingui } from '@lingui/react/macro'
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from 'react'
|
|
3
|
+
import type { Session } from '@atproto/oauth-provider-api'
|
|
4
|
+
import {
|
|
5
|
+
LayoutTitlePage,
|
|
6
|
+
LayoutTitlePageProps,
|
|
7
|
+
} from '../../../components/layouts/layout-title-page.tsx'
|
|
8
|
+
import { Override } from '../../../lib/util.ts'
|
|
9
|
+
import { SignInForm, SignInFormOutput } from './sign-in-form.tsx'
|
|
10
|
+
import { SignInPicker } from './sign-in-picker.tsx'
|
|
11
|
+
|
|
12
|
+
export type SignInViewProps = Override<
|
|
13
|
+
LayoutTitlePageProps,
|
|
14
|
+
{
|
|
15
|
+
sessions: readonly Session[]
|
|
16
|
+
selectSub: (sub: string | null) => void
|
|
17
|
+
loginHint?: string
|
|
18
|
+
|
|
19
|
+
onSignIn: (
|
|
20
|
+
credentials: SignInFormOutput,
|
|
21
|
+
signal: AbortSignal,
|
|
22
|
+
) => void | PromiseLike<void>
|
|
23
|
+
onForgotPassword?: (emailHint?: string) => void
|
|
24
|
+
onBack?: () => void
|
|
25
|
+
}
|
|
26
|
+
>
|
|
27
|
+
|
|
28
|
+
export function SignInView({
|
|
29
|
+
loginHint,
|
|
30
|
+
sessions,
|
|
31
|
+
selectSub,
|
|
32
|
+
|
|
33
|
+
onSignIn,
|
|
34
|
+
onForgotPassword,
|
|
35
|
+
onBack,
|
|
36
|
+
|
|
37
|
+
// LayoutTitlePage
|
|
38
|
+
title,
|
|
39
|
+
subtitle,
|
|
40
|
+
...props
|
|
41
|
+
}: SignInViewProps) {
|
|
42
|
+
const { t } = useLingui()
|
|
43
|
+
const session = useMemo(() => sessions.find((s) => s.selected), [sessions])
|
|
44
|
+
const clearSession = useCallback(() => selectSub(null), [selectSub])
|
|
45
|
+
const accounts = useMemo(() => sessions.map((s) => s.account), [sessions])
|
|
46
|
+
const [showSignInForm, setShowSignInForm] = useState(sessions.length === 0)
|
|
47
|
+
|
|
48
|
+
title ??= t`Sign in`
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
// Make sure the "back" action shows the account picker instead of the
|
|
52
|
+
// sign-in form (since the account was added to the list of current
|
|
53
|
+
// sessions).
|
|
54
|
+
if (session) setShowSignInForm(false)
|
|
55
|
+
}, [session])
|
|
56
|
+
|
|
57
|
+
if (session) {
|
|
58
|
+
// All set (parent view will handle the redirect)
|
|
59
|
+
if (!session.loginRequired) return null
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<LayoutTitlePage
|
|
63
|
+
{...props}
|
|
64
|
+
title={title}
|
|
65
|
+
subtitle={subtitle ?? <Trans>Confirm your password to continue</Trans>}
|
|
66
|
+
>
|
|
67
|
+
<SignInForm
|
|
68
|
+
onSubmit={onSignIn}
|
|
69
|
+
onForgotPassword={onForgotPassword}
|
|
70
|
+
onBack={clearSession}
|
|
71
|
+
usernameDefault={
|
|
72
|
+
session.account.preferred_username || session.account.sub
|
|
73
|
+
}
|
|
74
|
+
usernameReadonly={true}
|
|
75
|
+
rememberDefault={true}
|
|
76
|
+
/>
|
|
77
|
+
</LayoutTitlePage>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (loginHint) {
|
|
82
|
+
return (
|
|
83
|
+
<LayoutTitlePage
|
|
84
|
+
{...props}
|
|
85
|
+
title={title}
|
|
86
|
+
subtitle={subtitle ?? <Trans>Enter your password</Trans>}
|
|
87
|
+
>
|
|
88
|
+
<SignInForm
|
|
89
|
+
onSubmit={onSignIn}
|
|
90
|
+
onForgotPassword={onForgotPassword}
|
|
91
|
+
onBack={onBack}
|
|
92
|
+
usernameDefault={loginHint}
|
|
93
|
+
usernameReadonly={true}
|
|
94
|
+
/>
|
|
95
|
+
</LayoutTitlePage>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (sessions.length === 0) {
|
|
100
|
+
return (
|
|
101
|
+
<LayoutTitlePage
|
|
102
|
+
{...props}
|
|
103
|
+
title={title}
|
|
104
|
+
subtitle={subtitle ?? <Trans>Enter your username and password</Trans>}
|
|
105
|
+
>
|
|
106
|
+
<SignInForm
|
|
107
|
+
onSubmit={onSignIn}
|
|
108
|
+
onForgotPassword={onForgotPassword}
|
|
109
|
+
onBack={onBack}
|
|
110
|
+
/>
|
|
111
|
+
</LayoutTitlePage>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (showSignInForm) {
|
|
116
|
+
return (
|
|
117
|
+
<LayoutTitlePage
|
|
118
|
+
{...props}
|
|
119
|
+
title={title}
|
|
120
|
+
subtitle={subtitle ?? <Trans>Enter your username and password</Trans>}
|
|
121
|
+
>
|
|
122
|
+
<SignInForm
|
|
123
|
+
onSubmit={onSignIn}
|
|
124
|
+
onForgotPassword={onForgotPassword}
|
|
125
|
+
onBack={() => setShowSignInForm(false)}
|
|
126
|
+
/>
|
|
127
|
+
</LayoutTitlePage>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<LayoutTitlePage
|
|
133
|
+
{...props}
|
|
134
|
+
title={title}
|
|
135
|
+
subtitle={subtitle ?? <Trans>Select from an existing account</Trans>}
|
|
136
|
+
>
|
|
137
|
+
<SignInPicker
|
|
138
|
+
accounts={accounts}
|
|
139
|
+
onAccount={(a) => selectSub(a.sub)}
|
|
140
|
+
onOther={() => setShowSignInForm(true)}
|
|
141
|
+
onBack={onBack}
|
|
142
|
+
/>
|
|
143
|
+
</LayoutTitlePage>
|
|
144
|
+
)
|
|
145
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Trans, useLingui } from '@lingui/react/macro'
|
|
2
|
+
import { ReactNode, useEffect, useMemo, useRef, useState } from 'react'
|
|
3
|
+
import { Fieldset } from '../../../components/forms/fieldset.tsx'
|
|
4
|
+
import {
|
|
5
|
+
AsyncActionController,
|
|
6
|
+
FormCardAsync,
|
|
7
|
+
FormCardAsyncProps,
|
|
8
|
+
} from '../../../components/forms/form-card-async.tsx'
|
|
9
|
+
import { InputEmailAddress } from '../../../components/forms/input-email-address.tsx'
|
|
10
|
+
import { InputNewPassword } from '../../../components/forms/input-new-password.tsx'
|
|
11
|
+
import { InputText } from '../../../components/forms/input-text.tsx'
|
|
12
|
+
import { TokenIcon } from '../../../components/utils/icons.tsx'
|
|
13
|
+
import { mergeRefs } from '../../../lib/ref.ts'
|
|
14
|
+
import { Override } from '../../../lib/util.ts'
|
|
15
|
+
|
|
16
|
+
export type SignUpAccountFormOutput = {
|
|
17
|
+
email: string
|
|
18
|
+
password: string
|
|
19
|
+
inviteCode?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type SignUpAccountFormProps = Override<
|
|
23
|
+
Omit<
|
|
24
|
+
FormCardAsyncProps,
|
|
25
|
+
'append' | 'onCancel' | 'onSubmit' | 'submitLabel' | 'cancelLabel'
|
|
26
|
+
>,
|
|
27
|
+
{
|
|
28
|
+
inviteCodeRequired?: boolean
|
|
29
|
+
|
|
30
|
+
credentials?: SignUpAccountFormOutput
|
|
31
|
+
onCredentials?: (credentials?: SignUpAccountFormOutput) => void
|
|
32
|
+
|
|
33
|
+
onNext: (signal: AbortSignal) => void | PromiseLike<void>
|
|
34
|
+
nextLabel?: ReactNode
|
|
35
|
+
|
|
36
|
+
onPrev?: () => void
|
|
37
|
+
prevLabel?: ReactNode
|
|
38
|
+
}
|
|
39
|
+
>
|
|
40
|
+
|
|
41
|
+
export function SignUpAccountForm({
|
|
42
|
+
inviteCodeRequired = true,
|
|
43
|
+
|
|
44
|
+
credentials: creds,
|
|
45
|
+
onCredentials,
|
|
46
|
+
|
|
47
|
+
onNext,
|
|
48
|
+
nextLabel,
|
|
49
|
+
|
|
50
|
+
onPrev,
|
|
51
|
+
prevLabel,
|
|
52
|
+
|
|
53
|
+
// FormCardAsyncProps
|
|
54
|
+
children,
|
|
55
|
+
ref,
|
|
56
|
+
invalid,
|
|
57
|
+
...props
|
|
58
|
+
}: SignUpAccountFormProps) {
|
|
59
|
+
const { t } = useLingui()
|
|
60
|
+
|
|
61
|
+
const [email, setEmail] = useState(creds?.email)
|
|
62
|
+
const [password, setPassword] = useState(creds?.password)
|
|
63
|
+
const [inviteCode, setInviteCode] = useState(creds?.inviteCode)
|
|
64
|
+
|
|
65
|
+
const formRef = useRef<AsyncActionController>(null)
|
|
66
|
+
const resetForm = () => formRef.current?.reset()
|
|
67
|
+
|
|
68
|
+
const credentials = useMemo(
|
|
69
|
+
() =>
|
|
70
|
+
email && password && (!inviteCodeRequired || inviteCode)
|
|
71
|
+
? {
|
|
72
|
+
email,
|
|
73
|
+
password,
|
|
74
|
+
inviteCode: inviteCodeRequired ? inviteCode : undefined,
|
|
75
|
+
}
|
|
76
|
+
: undefined,
|
|
77
|
+
[email, password, inviteCode, inviteCodeRequired],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
onCredentials?.(credentials)
|
|
82
|
+
}, [credentials, onCredentials])
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<FormCardAsync
|
|
86
|
+
{...props}
|
|
87
|
+
ref={mergeRefs([ref, formRef])}
|
|
88
|
+
invalid={invalid || !credentials}
|
|
89
|
+
onCancel={onPrev}
|
|
90
|
+
cancelLabel={prevLabel}
|
|
91
|
+
onSubmit={onNext}
|
|
92
|
+
submitLabel={nextLabel}
|
|
93
|
+
append={children}
|
|
94
|
+
>
|
|
95
|
+
{inviteCodeRequired && (
|
|
96
|
+
<Fieldset label={<Trans>Invite code</Trans>}>
|
|
97
|
+
<InputText
|
|
98
|
+
icon={<TokenIcon className="w-5" />}
|
|
99
|
+
autoFocus
|
|
100
|
+
name="inviteCode"
|
|
101
|
+
title={t`Invite code`}
|
|
102
|
+
placeholder={t`example-com-xxxxx-xxxxx`}
|
|
103
|
+
required
|
|
104
|
+
value={inviteCode || ''}
|
|
105
|
+
onChange={(event) => {
|
|
106
|
+
setInviteCode(event.target.value || undefined)
|
|
107
|
+
resetForm()
|
|
108
|
+
}}
|
|
109
|
+
enterKeyHint="next"
|
|
110
|
+
/>
|
|
111
|
+
</Fieldset>
|
|
112
|
+
)}
|
|
113
|
+
|
|
114
|
+
<Fieldset label={<Trans>Email</Trans>}>
|
|
115
|
+
<InputEmailAddress
|
|
116
|
+
autoFocus={!inviteCodeRequired}
|
|
117
|
+
name="email"
|
|
118
|
+
enterKeyHint="next"
|
|
119
|
+
required
|
|
120
|
+
defaultValue={email}
|
|
121
|
+
onEmail={(email) => {
|
|
122
|
+
setEmail(email)
|
|
123
|
+
resetForm()
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
</Fieldset>
|
|
127
|
+
|
|
128
|
+
<Fieldset label={<Trans>Password</Trans>}>
|
|
129
|
+
<InputNewPassword
|
|
130
|
+
name="password"
|
|
131
|
+
enterKeyHint="next"
|
|
132
|
+
required
|
|
133
|
+
password={password}
|
|
134
|
+
onPassword={(value) => {
|
|
135
|
+
setPassword(value)
|
|
136
|
+
resetForm()
|
|
137
|
+
}}
|
|
138
|
+
/>
|
|
139
|
+
</Fieldset>
|
|
140
|
+
</FormCardAsync>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Trans } from '@lingui/react/macro'
|
|
2
|
+
import { JSX } from 'react'
|
|
3
|
+
import type { LinkDefinition } from '@atproto/oauth-provider-api'
|
|
4
|
+
import { LinkAnchor } from '../../../components/utils/link-anchor.tsx'
|
|
5
|
+
import { clsx } from '../../../lib/clsx.ts'
|
|
6
|
+
import { Override } from '../../../lib/util.ts'
|
|
7
|
+
|
|
8
|
+
export type SignUpDisclaimerProps = Override<
|
|
9
|
+
Omit<JSX.IntrinsicElements['p'], 'children'>,
|
|
10
|
+
{
|
|
11
|
+
links?: readonly LinkDefinition[]
|
|
12
|
+
}
|
|
13
|
+
>
|
|
14
|
+
|
|
15
|
+
export function SignUpDisclaimer({
|
|
16
|
+
links,
|
|
17
|
+
|
|
18
|
+
// p
|
|
19
|
+
className,
|
|
20
|
+
...attrs
|
|
21
|
+
}: SignUpDisclaimerProps) {
|
|
22
|
+
const tosLink = links?.find((l) => l.rel === 'terms-of-service')
|
|
23
|
+
const ppLink = links?.find((l) => l.rel === 'privacy-policy')
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<p
|
|
27
|
+
className={clsx('text-sm text-slate-500 dark:text-slate-400', className)}
|
|
28
|
+
{...attrs}
|
|
29
|
+
>
|
|
30
|
+
<Trans>
|
|
31
|
+
By creating an account you agree to the{' '}
|
|
32
|
+
{tosLink ? (
|
|
33
|
+
<LinkAnchor className="text-brand underline" link={tosLink}>
|
|
34
|
+
<Trans>Terms of Service</Trans>
|
|
35
|
+
</LinkAnchor>
|
|
36
|
+
) : (
|
|
37
|
+
<Trans>Terms of Service</Trans>
|
|
38
|
+
)}
|
|
39
|
+
{' and the '}
|
|
40
|
+
{ppLink ? (
|
|
41
|
+
<LinkAnchor className="text-brand underline" link={ppLink}>
|
|
42
|
+
<Trans>Privacy Policy</Trans>
|
|
43
|
+
</LinkAnchor>
|
|
44
|
+
) : (
|
|
45
|
+
<Trans>Privacy Policy</Trans>
|
|
46
|
+
)}{' '}
|
|
47
|
+
of this service.
|
|
48
|
+
</Trans>
|
|
49
|
+
</p>
|
|
50
|
+
)
|
|
51
|
+
}
|