🐛 Fix confirm account flow cannot get code from qs

This commit is contained in:
LittleSheep 2025-01-27 18:14:57 +08:00
parent dad48b7a60
commit 7600e3f93d
3 changed files with 16 additions and 4 deletions

View File

@ -1,3 +1,5 @@
'use client'
import { sni } from 'solar-js-sdk' import { sni } from 'solar-js-sdk'
import { Container, Box, Typography, CircularProgress, Alert, Collapse } from '@mui/material' import { Container, Box, Typography, CircularProgress, Alert, Collapse } from '@mui/material'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
@ -6,16 +8,18 @@ import { useEffect, useState } from 'react'
import ErrorIcon from '@mui/icons-material/Error' import ErrorIcon from '@mui/icons-material/Error'
import 'animate.css' import 'animate.css'
import { useSearchParams } from 'next/navigation'
export default function AccountConfirm() { export default function AccountConfirm() {
const router = useRouter() const router = useRouter()
const searchParams = useSearchParams()
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
async function confirm() { async function confirm() {
try { try {
await sni.post('/cgi/id/users/me/confirm', { await sni.post('/cgi/id/users/me/confirm', {
code: router.query['code'] as string, code: searchParams.get('code'),
}) })
router.push('/') router.push('/')
} catch (err: any) { } catch (err: any) {
@ -25,7 +29,7 @@ export default function AccountConfirm() {
useEffect(() => { useEffect(() => {
confirm() confirm()
}, []) }, [searchParams])
return ( return (
<Container <Container

View File

@ -1,12 +1,16 @@
'use client'
import { sni } from 'solar-js-sdk' import { sni } from 'solar-js-sdk'
import { Container, Box, Typography, Alert, Collapse, Button } from '@mui/material' import { Container, Box, Typography, Alert, Collapse, Button } from '@mui/material'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { useState } from 'react' import { useState } from 'react'
import ErrorIcon from '@mui/icons-material/Error' import ErrorIcon from '@mui/icons-material/Error'
import { useSearchParams } from 'next/navigation'
export default function AccountDeletion() { export default function AccountDeletion() {
const router = useRouter() const router = useRouter()
const searchParams = useSearchParams()
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
const [busy, setBusy] = useState(false) const [busy, setBusy] = useState(false)
@ -15,7 +19,7 @@ export default function AccountDeletion() {
try { try {
setBusy(true) setBusy(true)
await sni.patch('/cgi/id/users/me/deletion', { await sni.patch('/cgi/id/users/me/deletion', {
code: router.query['code'] as string, code: searchParams.get('code'),
}) })
router.push('/') router.push('/')
} catch (err: any) { } catch (err: any) {

View File

@ -1,3 +1,5 @@
'use client'
import { sni } from 'solar-js-sdk' import { sni } from 'solar-js-sdk'
import { Container, Box, Typography, Alert, Collapse, Button, TextField } from '@mui/material' import { Container, Box, Typography, Alert, Collapse, Button, TextField } from '@mui/material'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
@ -5,6 +7,7 @@ import { useState } from 'react'
import { useForm } from 'react-hook-form' import { useForm } from 'react-hook-form'
import ErrorIcon from '@mui/icons-material/Error' import ErrorIcon from '@mui/icons-material/Error'
import { useSearchParams } from 'next/navigation'
export type SnResetPasswordForm = { export type SnResetPasswordForm = {
password: string password: string
@ -12,6 +15,7 @@ export type SnResetPasswordForm = {
export default function AccountPasswordReset() { export default function AccountPasswordReset() {
const router = useRouter() const router = useRouter()
const searchParams = useSearchParams()
const { handleSubmit, register } = useForm<SnResetPasswordForm>() const { handleSubmit, register } = useForm<SnResetPasswordForm>()
@ -22,7 +26,7 @@ export default function AccountPasswordReset() {
try { try {
setBusy(true) setBusy(true)
await sni.patch('/cgi/id/users/me/password-reset', { await sni.patch('/cgi/id/users/me/password-reset', {
code: router.query['code'] as string, code: searchParams.get('code'),
new_password: data.password, new_password: data.password,
}) })
router.push('/') router.push('/')