diff --git a/src/Components/Auth/LoginPage.tsx b/src/Components/Auth/LoginPage.tsx index 14177275..d146bb73 100644 --- a/src/Components/Auth/LoginPage.tsx +++ b/src/Components/Auth/LoginPage.tsx @@ -1,8 +1,3 @@ -/* eslint-disable @typescript-eslint/no-misused-promises */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-floating-promises */ import { useEffect, useState } from 'react' import { Link, useNavigate } from 'react-router-dom' import { toast } from 'react-toastify' @@ -28,14 +23,14 @@ export function LoginPage() { success: { render({ data }) { navigate('/') - return `Hi ${data?.first_name}` + return `Hi ${data?.first_name ? data.first_name : 'Traveler'}` }, // other options icon: '✌️', }, error: { render({ data }) { - return `${data}` + return `${data as string}` }, autoClose: 10000, }, @@ -44,9 +39,10 @@ export function LoginPage() { } useEffect(() => { - const keyDownHandler = (event) => { + const keyDownHandler = (event: KeyboardEvent) => { if (event.key === 'Enter') { event.preventDefault() + // eslint-disable-next-line @typescript-eslint/no-floating-promises onLogin() } } @@ -86,6 +82,7 @@ export function LoginPage() { ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary' : 'tw-btn tw-btn-primary tw-btn-block' } + // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick={() => onLogin()} > {loading ? : 'Login'} diff --git a/src/Components/Auth/RequestPasswordPage.tsx b/src/Components/Auth/RequestPasswordPage.tsx index b26c70c2..4ebbce2c 100644 --- a/src/Components/Auth/RequestPasswordPage.tsx +++ b/src/Components/Auth/RequestPasswordPage.tsx @@ -1,6 +1,3 @@ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-misused-promises */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { toast } from 'react-toastify' @@ -12,8 +9,7 @@ import { useAuth } from './useAuth' /** * @category Auth */ -// eslint-disable-next-line react/prop-types -export function RequestPasswordPage({ resetUrl }) { +export function RequestPasswordPage({ resetUrl }: { resetUrl: string }) { const [email, setEmail] = useState('') const { requestPasswordReset, loading } = useAuth() @@ -32,7 +28,7 @@ export function RequestPasswordPage({ resetUrl }) { }, error: { render({ data }) { - return `${data}` + return `${data as string}` }, }, pending: 'sending email ...', @@ -56,6 +52,7 @@ export function RequestPasswordPage({ resetUrl }) { ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary' : 'tw-btn tw-btn-primary tw-btn-block' } + // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick={() => onReset()} > {loading ? : 'Send'} diff --git a/src/Components/Auth/SetNewPasswordPage.tsx b/src/Components/Auth/SetNewPasswordPage.tsx index 9bf33054..e38b10b9 100644 --- a/src/Components/Auth/SetNewPasswordPage.tsx +++ b/src/Components/Auth/SetNewPasswordPage.tsx @@ -1,5 +1,3 @@ -/* eslint-disable @typescript-eslint/no-misused-promises */ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { toast } from 'react-toastify' @@ -20,8 +18,6 @@ export function SetNewPasswordPage() { const onReset = async () => { const token = window.location.search.split('token=')[1] - // eslint-disable-next-line no-console - console.log(token) await toast.promise(passwordReset(token, password), { success: { @@ -32,7 +28,7 @@ export function SetNewPasswordPage() { }, error: { render({ data }) { - return `${data}` + return `${data as string}` }, }, pending: 'setting password ...', @@ -55,6 +51,7 @@ export function SetNewPasswordPage() { ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary' : 'tw-btn tw-btn-primary tw-btn-block' } + // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick={() => onReset()} > {loading ? : 'Set'} diff --git a/src/Components/Auth/SignupPage.tsx b/src/Components/Auth/SignupPage.tsx index 57c559c4..2e15481c 100644 --- a/src/Components/Auth/SignupPage.tsx +++ b/src/Components/Auth/SignupPage.tsx @@ -1,8 +1,3 @@ -/* eslint-disable @typescript-eslint/restrict-template-expressions */ -/* eslint-disable @typescript-eslint/no-floating-promises */ -/* eslint-disable @typescript-eslint/no-unsafe-call */ -/* eslint-disable @typescript-eslint/no-unsafe-member-access */ -/* eslint-disable @typescript-eslint/no-misused-promises */ import { useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' import { toast } from 'react-toastify' @@ -30,14 +25,14 @@ export function SignupPage() { success: { render({ data }) { navigate('/') - return `Hi ${data?.first_name}` + return `Hi ${data?.first_name ? data.first_name : 'Traveler'}` }, // other options icon: '✌️', }, error: { render({ data }) { - return `${data}` + return `${data as string}` }, autoClose: 10000, }, @@ -46,9 +41,10 @@ export function SignupPage() { } useEffect(() => { - const keyDownHandler = (event) => { + const keyDownHandler = (event: KeyboardEvent) => { if (event.key === 'Enter') { event.preventDefault() + // eslint-disable-next-line @typescript-eslint/no-floating-promises onRegister() } } @@ -88,6 +84,7 @@ export function SignupPage() { ? 'tw-btn tw-btn-disabled tw-btn-block tw-btn-primary' : 'tw-btn tw-btn-primary tw-btn-block' } + // eslint-disable-next-line @typescript-eslint/no-misused-promises onClick={() => onRegister()} > {loading ? : 'Sign Up'} diff --git a/src/Components/Auth/useAuth.tsx b/src/Components/Auth/useAuth.tsx index ffde8af5..60a8679f 100644 --- a/src/Components/Auth/useAuth.tsx +++ b/src/Components/Auth/useAuth.tsx @@ -1,8 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unsafe-return */ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ -/* eslint-disable @typescript-eslint/no-floating-promises */ -/* eslint-disable @typescript-eslint/no-explicit-any */ import { createContext, useState, useContext, useEffect } from 'react' import type { UserApi } from '#types/UserApi' @@ -28,11 +23,11 @@ interface AuthContextProps { login: (credentials: AuthCredentials) => Promise register: (credentials: AuthCredentials, userName: string) => Promise loading: boolean - logout: () => Promise - updateUser: (user: UserItem) => any - token: string | null - requestPasswordReset: (email: string, reset_url: string) => Promise - passwordReset: (token: string, new_password: string) => Promise + logout: () => Promise + updateUser: (user: UserItem) => Promise + token: string | undefined + requestPasswordReset: (email: string, reset_url: string) => Promise + passwordReset: (token: string, new_password: string) => Promise } const AuthContext = createContext({ @@ -53,12 +48,13 @@ const AuthContext = createContext({ */ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { const [user, setUser] = useState(null) - const [token, setToken] = useState(null) + const [token, setToken] = useState() const [loading, setLoading] = useState(false) const isAuthenticated = !!user useEffect(() => { setLoading(true) + // eslint-disable-next-line @typescript-eslint/no-floating-promises loadUser() setLoading(false) // eslint-disable-next-line react-hooks/exhaustive-deps @@ -84,10 +80,10 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { const login = async (credentials: AuthCredentials): Promise => { setLoading(true) try { - const res = await userApi.login(credentials.email, credentials.password) - setToken(res?.access_token) + const user = await userApi.login(credentials.email, credentials.password) + setToken(user?.access_token) return await loadUser() - } catch (error: any) { + } catch (error) { setLoading(false) throw error } @@ -95,13 +91,13 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { const register = async ( credentials: AuthCredentials, - userName, + userName: string, ): Promise => { setLoading(true) try { /* const res = */ await userApi.register(credentials.email, credentials.password, userName) return await login(credentials) - } catch (error: any) { + } catch (error) { setLoading(false) throw error } @@ -111,7 +107,7 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { try { await userApi.logout() setUser(null) - } catch (error: any) { + } catch (error) { setLoading(false) throw error } @@ -119,37 +115,35 @@ export const AuthProvider = ({ userApi, children }: AuthProviderProps) => { const updateUser = async (user: UserItem) => { setLoading(true) - const { id, ...userRest } = user - try { - const res = await userApi.updateUser(userRest) - setUser(res as any) - loadUser() + const updatedUser = await userApi.updateUser(user) + setUser(updatedUser) + await loadUser() setLoading(false) - return res as any - } catch (error: any) { + return updatedUser + } catch (error) { setLoading(false) throw error } } - const requestPasswordReset = async (email: string, resetUrl?: string): Promise => { + const requestPasswordReset = async (email: string, resetUrl?: string): Promise => { setLoading(true) try { await userApi.requestPasswordReset(email, resetUrl) return setLoading(false) - } catch (error: any) { + } catch (error) { setLoading(false) throw error } } - const passwordReset = async (token: string, newPassword: string): Promise => { + const passwordReset = async (token: string, newPassword: string): Promise => { setLoading(true) try { await userApi.passwordReset(token, newPassword) return setLoading(false) - } catch (error: any) { + } catch (error) { setLoading(false) throw error } diff --git a/src/Components/Profile/UserSettings.tsx b/src/Components/Profile/UserSettings.tsx index 0b2da6cb..0e974cd6 100644 --- a/src/Components/Profile/UserSettings.tsx +++ b/src/Components/Profile/UserSettings.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ import { useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' diff --git a/src/types/UserApi.d.ts b/src/types/UserApi.d.ts index a35e079d..98fb64db 100644 --- a/src/types/UserApi.d.ts +++ b/src/types/UserApi.d.ts @@ -8,8 +8,8 @@ export interface UserApi { login(email: string, password: string): Promise logout(): Promise getUser(): Promise - getToken(): Promise - updateUser(user: UserItem): Promise + getToken(): Promise + updateUser(user: UserItem): Promise requestPasswordReset(email: string, reset_url?: string) passwordReset(token: string, new_password: string) } diff --git a/src/types/UserItem.d.ts b/src/types/UserItem.d.ts index 68ccb8d7..00942294 100644 --- a/src/types/UserItem.d.ts +++ b/src/types/UserItem.d.ts @@ -11,6 +11,7 @@ export interface UserItem { password?: string profile?: Profile first_name?: string + access_token?: string // eslint-disable-next-line @typescript-eslint/no-explicit-any [key: string]: any }