mirror of
https://github.com/Myzel394/kleckrelay-website.git
synced 2025-06-19 15:55:26 +02:00
fix: Adapt APIs to upstream APIs
This commit is contained in:
parent
17673852dd
commit
7120c2d55b
@ -10,7 +10,7 @@ export interface UpdateAccountData {
|
||||
}
|
||||
|
||||
export default async function updateAccount(updateData: UpdateAccountData): Promise<ServerUser> {
|
||||
const {data} = await client.patch(
|
||||
const {data: user} = await client.patch(
|
||||
`${import.meta.env.VITE_SERVER_BASE_URL}/v1/account`,
|
||||
updateData,
|
||||
{
|
||||
@ -18,5 +18,5 @@ export default async function updateAccount(updateData: UpdateAccountData): Prom
|
||||
},
|
||||
)
|
||||
|
||||
return parseUser(data.user)
|
||||
return parseUser(user)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ export interface VerifyEmailData {
|
||||
}
|
||||
|
||||
export default async function verifyEmail({email, token}: VerifyEmailData): Promise<ServerUser> {
|
||||
const {data} = await client.post(
|
||||
const {data: user} = await client.post(
|
||||
`${import.meta.env.VITE_SERVER_BASE_URL}/v1/auth/verify-email`,
|
||||
{
|
||||
email: email,
|
||||
@ -19,5 +19,5 @@ export default async function verifyEmail({email, token}: VerifyEmailData): Prom
|
||||
},
|
||||
)
|
||||
|
||||
return parseUser(data.user)
|
||||
return parseUser(user)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ export default async function verifyLoginWithEmail({
|
||||
token,
|
||||
sameRequestToken,
|
||||
}: VerifyLoginWithEmailData): Promise<ServerUser> {
|
||||
const {data} = await client.post(
|
||||
const {data: user} = await client.post(
|
||||
`${import.meta.env.VITE_SERVER_BASE_URL}/v1/auth/login/email-token/verify`,
|
||||
{
|
||||
email,
|
||||
@ -25,5 +25,5 @@ export default async function verifyLoginWithEmail({
|
||||
},
|
||||
)
|
||||
|
||||
return parseUser(data.user)
|
||||
return parseUser(user)
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ import {AxiosError} from "axios"
|
||||
|
||||
import {useMutation, useQuery} from "@tanstack/react-query"
|
||||
|
||||
import {REFRESH_TOKEN_URL, RefreshTokenResult, getMe, refreshToken} from "~/apis"
|
||||
import {AuthenticationDetails, ServerUser, User} from "~/server-types"
|
||||
import {REFRESH_TOKEN_URL, getMe, refreshToken} from "~/apis"
|
||||
import {ServerUser, User} from "~/server-types"
|
||||
import {client} from "~/constants/axios-client"
|
||||
|
||||
export interface UseAuthData {
|
||||
@ -22,11 +22,11 @@ export default function useUser({
|
||||
user,
|
||||
updateUser,
|
||||
}: UseAuthData) {
|
||||
const {mutateAsync: refresh} = useMutation<RefreshTokenResult, AxiosError, void>(refreshToken, {
|
||||
onError: () => logout(),
|
||||
const {mutateAsync: refresh} = useMutation<ServerUser, AxiosError, void>(refreshToken, {
|
||||
onError: logout,
|
||||
})
|
||||
|
||||
useQuery<AuthenticationDetails, AxiosError>(["get_me"], getMe, {
|
||||
useQuery<ServerUser, AxiosError>(["get_me"], getMe, {
|
||||
refetchOnWindowFocus: "always",
|
||||
refetchOnReconnect: "always",
|
||||
retry: 2,
|
||||
|
@ -13,7 +13,7 @@ import {useMutation} from "@tanstack/react-query"
|
||||
import {AuthContext, PasswordField, SimpleForm} from "~/components"
|
||||
import {setupEncryptionForUser} from "~/utils"
|
||||
import {useExtensionHandler, useNavigateToNext, useSystemPreferredTheme, useUser} from "~/hooks"
|
||||
import {AuthenticationDetails, ServerSettings} from "~/server-types"
|
||||
import {ServerSettings, ServerUser} from "~/server-types"
|
||||
import {UpdateAccountData, updateAccount} from "~/apis"
|
||||
|
||||
export interface PasswordFormProps {
|
||||
@ -51,9 +51,7 @@ export default function PasswordForm({onDone}: PasswordFormProps): ReactElement
|
||||
|
||||
const {_setEncryptionPassword, login} = useContext(AuthContext)
|
||||
|
||||
const {mutateAsync} = useMutation<AuthenticationDetails, AxiosError, UpdateAccountData>(
|
||||
updateAccount,
|
||||
)
|
||||
const {mutateAsync} = useMutation<ServerUser, AxiosError, UpdateAccountData>(updateAccount)
|
||||
const formik = useFormik<Form>({
|
||||
validationSchema: schema,
|
||||
initialValues: {
|
||||
@ -83,7 +81,7 @@ export default function PasswordForm({onDone}: PasswordFormProps): ReactElement
|
||||
encryptedNotes,
|
||||
},
|
||||
{
|
||||
onSuccess: ({user: newUser}) => {
|
||||
onSuccess: newUser => {
|
||||
login(newUser)
|
||||
_setEncryptionPassword(encryptionPassword)
|
||||
navigateToNext()
|
||||
|
@ -24,12 +24,7 @@ import {
|
||||
} from "@mui/material"
|
||||
import {LoadingButton} from "@mui/lab"
|
||||
|
||||
import {
|
||||
AuthenticationDetails,
|
||||
ServerSettings,
|
||||
ServerUser,
|
||||
SimpleDetailResponse,
|
||||
} from "~/server-types"
|
||||
import {ServerSettings, ServerUser, SimpleDetailResponse} from "~/server-types"
|
||||
import {VerifyLoginWithEmailData, verifyLoginWithEmail} from "~/apis"
|
||||
import {MultiStepFormElement} from "~/components"
|
||||
import {parseFastAPIError} from "~/utils"
|
||||
@ -84,10 +79,10 @@ export default function ConfirmCodeForm({
|
||||
.label(t("routes.LoginRoute.forms.confirmCode.form.code.label")),
|
||||
})
|
||||
|
||||
const {mutateAsync} = useMutation<AuthenticationDetails, AxiosError, VerifyLoginWithEmailData>(
|
||||
const {mutateAsync} = useMutation<ServerUser, AxiosError, VerifyLoginWithEmailData>(
|
||||
verifyLoginWithEmail,
|
||||
{
|
||||
onSuccess: ({user}) => onConfirm(user),
|
||||
onSuccess: onConfirm,
|
||||
},
|
||||
)
|
||||
const formik = useFormik<Form>({
|
||||
|
@ -6,7 +6,7 @@ import {useTranslation} from "react-i18next"
|
||||
import {useMutation} from "@tanstack/react-query"
|
||||
import {Box, Grid, Paper, Typography} from "@mui/material"
|
||||
|
||||
import {AuthenticationDetails, ServerUser} from "~/server-types"
|
||||
import {ServerUser} from "~/server-types"
|
||||
import {verifyLoginWithEmail} from "~/apis"
|
||||
import {LoadingData} from "~/components"
|
||||
|
||||
@ -23,14 +23,14 @@ export default function ConfirmFromDifferentDevice({
|
||||
onConfirm,
|
||||
}: ConfirmFromDifferentDeviceProps): ReactElement {
|
||||
const {t} = useTranslation()
|
||||
const {mutate, isLoading, isError} = useMutation<AuthenticationDetails, AxiosError, void>(
|
||||
const {mutate, isLoading, isError} = useMutation<ServerUser, AxiosError, void>(
|
||||
() =>
|
||||
verifyLoginWithEmail({
|
||||
email,
|
||||
token,
|
||||
}),
|
||||
{
|
||||
onSuccess: ({user}) => onConfirm(user),
|
||||
onSuccess: onConfirm,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -9,7 +9,7 @@ import React, {ReactElement, useContext} from "react"
|
||||
import {Grid, Paper, Typography, useTheme} from "@mui/material"
|
||||
import {useMutation} from "@tanstack/react-query"
|
||||
|
||||
import {AuthenticationDetails, ServerSettings} from "~/server-types"
|
||||
import {ServerSettings, ServerUser} from "~/server-types"
|
||||
import {VerifyEmailData, verifyEmail} from "~/apis"
|
||||
import {useQueryParams} from "~/hooks"
|
||||
import {AuthContext} from "~/components"
|
||||
@ -41,15 +41,12 @@ export default function VerifyEmailRoute(): ReactElement {
|
||||
|
||||
return token.split("").every(char => chars.includes(char))
|
||||
})
|
||||
const {mutateAsync} = useMutation<AuthenticationDetails, AxiosError, VerifyEmailData>(
|
||||
verifyEmail,
|
||||
{
|
||||
onSuccess: ({user}) => {
|
||||
login(user)
|
||||
navigate("/auth/complete-account")
|
||||
},
|
||||
const {mutateAsync} = useMutation<ServerUser, AxiosError, VerifyEmailData>(verifyEmail, {
|
||||
onSuccess: user => {
|
||||
login(user)
|
||||
navigate("/auth/complete-account")
|
||||
},
|
||||
)
|
||||
})
|
||||
const {loading} = useAsync(async () => {
|
||||
await emailSchema.validate(email)
|
||||
await tokenSchema.validate(token)
|
||||
|
Loading…
x
Reference in New Issue
Block a user