feat: put token into headers

This commit is contained in:
DIYgod
2025-03-07 21:29:07 +08:00
parent ea53d1b9b5
commit 00c807f86d
7 changed files with 80 additions and 7 deletions
+1
View File
@@ -55,6 +55,7 @@
"@sentry/vite-plugin": "3.1.2",
"@types/html-minifier-terser": "7.0.2",
"@types/js-yaml": "4.0.9",
"@types/react-google-recaptcha": "2.1.9",
"@vitejs/plugin-legacy": "6.0.1",
"@vitejs/plugin-react": "4.3.4",
"autoprefixer": "10.4.20",
@@ -10,6 +10,8 @@ import {
import { Input } from "@follow/components/ui/input/Input.js"
import { env } from "@follow/shared/env.desktop"
import { zodResolver } from "@hookform/resolvers/zod"
import { useRef } from "react"
import ReCAPTCHA from "react-google-recaptcha"
import { useForm } from "react-hook-form"
import { useTranslation } from "react-i18next"
import { toast } from "sonner"
@@ -167,7 +169,10 @@ function RegisterForm() {
const { isValid } = form.formState
function onSubmit(values: z.infer<typeof registerFormSchema>) {
const recaptchaRef = useRef<ReCAPTCHA>(null)
async function onSubmit(values: z.infer<typeof registerFormSchema>) {
const token = await recaptchaRef.current?.executeAsync()
return signUp.email({
email: values.email,
password: values.password,
@@ -180,6 +185,9 @@ function RegisterForm() {
onError(context) {
toast.error(context.error.message)
},
headers: {
"x-token": `r2:${token}`,
},
},
})
}
@@ -227,6 +235,13 @@ function RegisterForm() {
</FormItem>
)}
/>
{env.VITE_RECAPTCHA_V2_SITE_KEY && (
<ReCAPTCHA
ref={recaptchaRef}
sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY}
size="invisible"
/>
)}
<Button disabled={!isValid} type="submit" className="w-full" size="lg">
{t("register.submit")}
</Button>
@@ -92,7 +92,17 @@ export const useClaimWalletDailyRewardMutation = () => {
return useMutation({
mutationKey: ["claimWalletDailyReward"],
mutationFn: ({ tokenV2, tokenV3 }: { tokenV2?: string; tokenV3?: string }) =>
apiClient.wallets.transactions.claim_daily.$post({ json: { t2: tokenV2, t3: tokenV3 } }),
apiClient.wallets.transactions.claim_daily.$post(
{ json: {} },
{
headers:
tokenV2 || tokenV3
? {
"x-token": tokenV2 ? `r2:${tokenV2}` : `r3:${tokenV3}`,
}
: undefined,
},
),
async onError(err) {
toastFetchError(err)
},
+1
View File
@@ -84,6 +84,7 @@
"react-native-awesome-slider": "2.9.0",
"react-native-bouncy-checkbox": "4.1.2",
"react-native-color-matrix-image-filters": "7.0.2",
"react-native-device-info": "14.0.4",
"react-native-gesture-handler": "2.24.0",
"react-native-image-colors": "2.4.0",
"react-native-ios-context-menu": "3.1.0",
+17 -1
View File
@@ -10,7 +10,10 @@ import {
FormMessage,
} from "@follow/components/ui/form/index.jsx"
import { Input } from "@follow/components/ui/input/index.js"
import { env } from "@follow/shared/env.desktop"
import { zodResolver } from "@hookform/resolvers/zod"
import { useRef } from "react"
import ReCAPTCHA from "react-google-recaptcha"
import { useForm } from "react-hook-form"
import { Trans, useTranslation } from "react-i18next"
import { Link, useNavigate } from "react-router"
@@ -53,7 +56,10 @@ function RegisterForm() {
const navigate = useNavigate()
function onSubmit(values: z.infer<typeof formSchema>) {
const recaptchaRef = useRef<ReCAPTCHA>(null)
async function onSubmit(values: z.infer<typeof formSchema>) {
const token = await recaptchaRef.current?.executeAsync()
return signUp.email({
email: values.email,
password: values.password,
@@ -66,6 +72,9 @@ function RegisterForm() {
onError(context) {
toast.error(context.error.message)
},
headers: {
"x-token": `r2:${token}`,
},
},
})
}
@@ -129,6 +138,13 @@ function RegisterForm() {
</FormItem>
)}
/>
{env.VITE_RECAPTCHA_V2_SITE_KEY && (
<ReCAPTCHA
ref={recaptchaRef}
sitekey={env.VITE_RECAPTCHA_V2_SITE_KEY}
size="invisible"
/>
)}
<Button disabled={!isValid} type="submit" className="w-full" size="lg">
{t("register.submit")}
</Button>
+2
View File
@@ -28,6 +28,7 @@
"ofetch": "1.4.1",
"rc-modal-sheet": "0.3.2",
"react-blurhash": "0.3.0",
"react-google-recaptcha": "3.1.0",
"react-hook-form": "7.54.2",
"react-hotkeys-hook": "4.6.1",
"react-i18next": "15.4.1",
@@ -49,6 +50,7 @@
"@follow/utils": "workspace:*",
"@radix-ui/react-avatar": "1.1.3",
"@types/html-minifier-terser": "7.0.2",
"@types/react-google-recaptcha": "2.1.9",
"chokidar": "4.0.3",
"daisyui": "4.12.23",
"dotenv-flow": "4.1.0",
+32 -4
View File
@@ -278,6 +278,9 @@ importers:
'@types/js-yaml':
specifier: 4.0.9
version: 4.0.9
'@types/react-google-recaptcha':
specifier: 2.1.9
version: 2.1.9
'@vitejs/plugin-legacy':
specifier: 6.0.1
version: 6.0.1(terser@5.39.0)(vite@6.1.0(@types/node@22.13.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.39.0)(tsx@4.19.3)(yaml@2.7.0))
@@ -949,6 +952,9 @@ importers:
react-native-color-matrix-image-filters:
specifier: 7.0.2
version: 7.0.2(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)
react-native-device-info:
specifier: 14.0.4
version: 14.0.4(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))
react-native-gesture-handler:
specifier: 2.24.0
version: 2.24.0(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1)
@@ -1124,6 +1130,9 @@ importers:
react-blurhash:
specifier: 0.3.0
version: 0.3.0(blurhash@2.0.5)(react@18.3.1)
react-google-recaptcha:
specifier: 3.1.0
version: 3.1.0(react@18.3.1)
react-hook-form:
specifier: 7.54.2
version: 7.54.2(react@18.3.1)
@@ -1182,6 +1191,9 @@ importers:
'@types/html-minifier-terser':
specifier: 7.0.2
version: 7.0.2
'@types/react-google-recaptcha':
specifier: 2.1.9
version: 2.1.9
chokidar:
specifier: 4.0.3
version: 4.0.3
@@ -4132,7 +4144,7 @@ packages:
'@radix-ui/react-compose-refs@1.1.1':
resolution: {integrity: sha512-Y9VzoRDSJtgFMUCoiZBDVo084VQ5hfpXxVE+NgkdNsjiDBByiImMZKKhxMwCbdHvhlENG6a833CbFkOQvTricw==}
peerDependencies:
'@types/react': '*'
'@types/react': npm:@types/react@18.3.12
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
@@ -4154,7 +4166,7 @@ packages:
'@radix-ui/react-context@1.1.1':
resolution: {integrity: sha512-UASk9zi+crv9WteK/NU4PLvOoL3OuE6BWVKNF6hPRBtYBDXQ2u5iu3O59zUlJiTVvkyuycnqrztsHVJwcK9K+Q==}
peerDependencies:
'@types/react': '*'
'@types/react': npm:@types/react@18.3.12
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
@@ -4211,7 +4223,7 @@ packages:
'@radix-ui/react-focus-guards@1.1.1':
resolution: {integrity: sha512-pSIwfrT1a6sIoDASCSpFwOasEwKTZWDw/iBdtnqKO7v6FeOzYJ7U53cPzYFVR3geGGXgVHaH+CdngrrAzqUGxg==}
peerDependencies:
'@types/react': '*'
'@types/react': npm:@types/react@18.3.12
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
@@ -4499,7 +4511,7 @@ packages:
'@radix-ui/react-use-controllable-state@1.1.0':
resolution: {integrity: sha512-MtfMVJiSr2NjzS0Aa90NPTnvTSg6C/JLCV7ma0W6+OMV78vd8OyRpID+Ng9LxzsPbLeuBnWBA1Nq30AtBIDChw==}
peerDependencies:
'@types/react': '*'
'@types/react': npm:@types/react@18.3.12
react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc
peerDependenciesMeta:
'@types/react':
@@ -5590,6 +5602,9 @@ packages:
'@types/react-dom@18.3.1':
resolution: {integrity: sha512-qW1Mfv8taImTthu4KoXgDfLuk4bydU6Q/TkADnDWWHwi4NX4BR+LWfTp2sVmTqRrsHvyDDTelgelxJ+SsejKKQ==}
'@types/react-google-recaptcha@2.1.9':
resolution: {integrity: sha512-nT31LrBDuoSZJN4QuwtQSF3O89FVHC4jLhM+NtKEmVF5R1e8OY0Jo4//x2Yapn2aNHguwgX5doAq8Zo+Ehd0ug==}
'@types/react@18.3.12':
resolution: {integrity: sha512-D2wOSq/d6Agt28q7rSI3jhU7G6aiuzljDGZ2hTZHIkrTLUI+AF3WMeKkEZ9nN2fkBAlcktT6vcZjDFiIhMYEQw==}
@@ -12623,6 +12638,11 @@ packages:
react-native-svg:
optional: true
react-native-device-info@14.0.4:
resolution: {integrity: sha512-NX0wMAknSDBeFnEnSFQ8kkAcQrFHrG4Cl0mVjoD+0++iaKrOupiGpBXqs8xR0SeJyPC5zpdPl4h/SaBGly6UxA==}
peerDependencies:
react-native: '*'
react-native-drawer-layout@4.1.1:
resolution: {integrity: sha512-ob6O3ph7PZ3A2FpdlsSxHuMpHDXREZPR8A6S3q0dSxV7i6d+8Z6CPCTbegfN2QZyizSow9NLrKyXP93tlqZ3dA==}
peerDependencies:
@@ -20968,6 +20988,10 @@ snapshots:
dependencies:
'@types/react': 18.3.12
'@types/react-google-recaptcha@2.1.9':
dependencies:
'@types/react': 18.3.12
'@types/react@18.3.12':
dependencies:
'@types/prop-types': 15.7.14
@@ -29711,6 +29735,10 @@ snapshots:
transitivePeerDependencies:
- supports-color
react-native-device-info@14.0.4(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)):
dependencies:
react-native: 0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5)
react-native-drawer-layout@4.1.1(react-native-gesture-handler@2.24.0(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native-reanimated@3.16.7(@babel/core@7.26.9)(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1))(react-native@0.77.0(@babel/core@7.26.9)(@babel/preset-env@7.26.9(@babel/core@7.26.9))(@types/react@18.3.12)(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@6.0.5))(react@18.3.1):
dependencies:
react: 18.3.1