From 40b80b65b31dc34cd8b35aa7742eddb44a06473e Mon Sep 17 00:00:00 2001 From: nflnkr Date: Wed, 17 May 2023 16:18:26 +0300 Subject: [PATCH] remove useless code --- src/api/auth.ts | 40 +++++++++------------------------------ src/index.tsx | 6 ++---- src/model/auth.ts | 7 ------- src/pages/auth/Signin.tsx | 4 +--- src/pages/auth/Signup.tsx | 4 +--- src/stores/user.ts | 6 ------ 6 files changed, 13 insertions(+), 54 deletions(-) diff --git a/src/api/auth.ts b/src/api/auth.ts index 25fa658..eeee66c 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,4 +1,4 @@ -import { CreateUserRequest, User } from "@root/model/auth"; +import { User } from "@root/model/auth"; import { authStore } from "@root/stores/makeRequest"; @@ -7,38 +7,16 @@ const authUrl = process.env.NODE_ENV === "production" ? "/auth" : "https://hub.p const makeRequest = authStore.getState().makeRequest; -export async function getOrCreateUser({ userId, email, password }: { +export async function getOrCreateUser({ userId }: { userId: string; - email: string | null; - password: string | null; }): Promise { - try { - return await makeRequest({ - url: `${apiUrl}/${userId}`, - contentType: true, - method: "GET", - useToken: false, - withCredentials: false, - }); - } catch (error) { - console.log("get user error", error); - - if (!email || !password) return null; - - return makeRequest({ - url: apiUrl, - contentType: true, - method: "POST", - useToken: true, - withCredentials: false, - body: { - email, - login: email, - password, - phoneNumber: "-", - } - }); - } + return makeRequest({ + url: `${apiUrl}/${userId}`, + contentType: true, + method: "GET", + useToken: false, + withCredentials: false, + }); } export function logout() { diff --git a/src/index.tsx b/src/index.tsx index f2c225b..cf4bc07 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -28,19 +28,17 @@ import { setUser, useUserStore } from "./stores/user"; const App = () => { const location = useLocation(); const userId = useUserStore(state => state.userId); - const email = useUserStore(state => state.email); - const password = useUserStore(state => state.password); useEffect(function fetchUserData() { if (!userId) return; - getOrCreateUser({ userId, email, password }).then(result => { + getOrCreateUser({ userId }).then(result => { setUser(result); }).catch(error => { console.log("Error fetching user", error); enqueueSnackbar(error.response?.data?.message ?? error.message ?? "Error fetching user"); }); - }, [email, password, userId]); + }, [userId]); const state = (location.state as { backgroundLocation?: Location; }); diff --git a/src/model/auth.ts b/src/model/auth.ts index 09c4d97..ddd0dd3 100644 --- a/src/model/auth.ts +++ b/src/model/auth.ts @@ -23,13 +23,6 @@ export interface LoginRequest { export type LoginResponse = RegisterResponse; -export interface CreateUserRequest { - login: string; - email: string; - password: string; - phoneNumber: string; -}; - export interface User { _id: string; login: string; diff --git a/src/pages/auth/Signin.tsx b/src/pages/auth/Signin.tsx index fb1a2a8..f727df2 100644 --- a/src/pages/auth/Signin.tsx +++ b/src/pages/auth/Signin.tsx @@ -11,7 +11,7 @@ import { Link as RouterLink } from "react-router-dom"; import { object, string } from "yup"; import { useState } from "react"; import { LoginRequest, LoginResponse } from "@root/model/auth"; -import { setUserId, setUserEmail, setUserPassword } from "@root/stores/user"; +import { setUserId } from "@root/stores/user"; interface Values { @@ -50,8 +50,6 @@ export default function SigninDialog() { withCredentials: true, }).then(result => { setUserId(result._id); - setUserEmail(result.email); - setUserPassword(values.password); navigate("/tariffs"); }).catch((error: any) => { enqueueSnackbar(error.response?.data?.message ?? error.message ?? "Unknown error"); diff --git a/src/pages/auth/Signup.tsx b/src/pages/auth/Signup.tsx index fdf9b5b..6cfde6e 100644 --- a/src/pages/auth/Signup.tsx +++ b/src/pages/auth/Signup.tsx @@ -11,7 +11,7 @@ import { Link as RouterLink } from "react-router-dom"; import { object, ref, string } from "yup"; import { useState } from "react"; import { RegisterRequest, RegisterResponse } from "@root/model/auth"; -import { setUserEmail, setUserPassword, setUserId } from "@root/stores/user"; +import { setUserId } from "@root/stores/user"; interface Values { @@ -55,8 +55,6 @@ export default function SignupDialog() { withCredentials: true, }).then(result => { setUserId(result._id); - setUserEmail(result.email); - setUserPassword(values.password); navigate("/tariffs"); }).catch((error: any) => { enqueueSnackbar(error.response?.data?.message ?? error.message ?? "Unknown error"); diff --git a/src/stores/user.ts b/src/stores/user.ts index 695bec8..03a9c9d 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -5,15 +5,11 @@ import { createJSONStorage, devtools, persist } from "zustand/middleware"; interface UserStore { userId: string | null; - email: string | null; - password: string | null; user: User | null; } const initialState: UserStore = { userId: null, - email: null, - password: null, user: null, }; @@ -36,8 +32,6 @@ export const useUserStore = create()( ); export const setUserId = (userId: string | null) => useUserStore.setState({ userId }); -export const setUserEmail = (email: string | null) => useUserStore.setState({ email }); -export const setUserPassword = (password: string | null) => useUserStore.setState({ password }); export const setUser = (user: User | null) => useUserStore.setState({ user }); export const clearUser = () => useUserStore.setState({ ...initialState }); \ No newline at end of file