mirror of
https://github.com/fastapi/full-stack-fastapi-template.git
synced 2026-11-03 20:36:27 +00:00
Migrate useAuth to new client API
This commit is contained in:
@@ -22,13 +22,13 @@ const useAuth = () => {
|
|||||||
|
|
||||||
const { data: user } = useQuery<UserPublic | null, Error>({
|
const { data: user } = useQuery<UserPublic | null, Error>({
|
||||||
queryKey: ["currentUser"],
|
queryKey: ["currentUser"],
|
||||||
queryFn: UsersService.readUserMe,
|
queryFn: async () => (await UsersService.readUserMe()).data,
|
||||||
enabled: isLoggedIn(),
|
enabled: isLoggedIn(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const signUpMutation = useMutation({
|
const signUpMutation = useMutation({
|
||||||
mutationFn: (data: UserRegister) =>
|
mutationFn: (data: UserRegister) =>
|
||||||
UsersService.registerUser({ requestBody: data }),
|
UsersService.registerUser({ body: data }),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
navigate({ to: "/login" })
|
navigate({ to: "/login" })
|
||||||
},
|
},
|
||||||
@@ -40,9 +40,9 @@ const useAuth = () => {
|
|||||||
|
|
||||||
const login = async (data: AccessToken) => {
|
const login = async (data: AccessToken) => {
|
||||||
const response = await LoginService.loginAccessToken({
|
const response = await LoginService.loginAccessToken({
|
||||||
formData: data,
|
body: data,
|
||||||
})
|
})
|
||||||
localStorage.setItem("access_token", response.access_token)
|
localStorage.setItem("access_token", response.data.access_token)
|
||||||
}
|
}
|
||||||
|
|
||||||
const loginMutation = useMutation({
|
const loginMutation = useMutation({
|
||||||
|
|||||||
Reference in New Issue
Block a user