🆙 Update React Query to TanStack Query (#1153)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useNavigate } from "@tanstack/react-router"
|
||||
import { useState } from "react"
|
||||
import { useMutation, useQuery } from "react-query"
|
||||
import { useMutation, useQuery } from "@tanstack/react-query"
|
||||
|
||||
import {
|
||||
type Body_login_login_access_token as AccessToken,
|
||||
@@ -17,13 +17,11 @@ const isLoggedIn = () => {
|
||||
const useAuth = () => {
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const navigate = useNavigate()
|
||||
const { data: user, isLoading } = useQuery<UserOut | null, Error>(
|
||||
"currentUser",
|
||||
UsersService.readUserMe,
|
||||
{
|
||||
enabled: isLoggedIn(),
|
||||
},
|
||||
)
|
||||
const { data: user, isLoading } = useQuery<UserOut | null, Error>({
|
||||
queryKey: ["currentUser"],
|
||||
queryFn: UsersService.readUserMe,
|
||||
enabled: isLoggedIn(),
|
||||
})
|
||||
|
||||
const login = async (data: AccessToken) => {
|
||||
const response = await LoginService.loginAccessToken({
|
||||
@@ -32,7 +30,8 @@ const useAuth = () => {
|
||||
localStorage.setItem("access_token", response.access_token)
|
||||
}
|
||||
|
||||
const loginMutation = useMutation(login, {
|
||||
const loginMutation = useMutation({
|
||||
mutationFn: login,
|
||||
onSuccess: () => {
|
||||
navigate({ to: "/" })
|
||||
},
|
||||
|
Reference in New Issue
Block a user