) => {
e.preventDefault()
@@ -105,14 +57,13 @@ const Layout = ({
return (
<>
-
{(!user && !loading) || (user && user.verified) ? (
{children}
) : (
!loading && (
{strings.VALIDATE_EMAIL}
-
diff --git a/frontend/src/context/UserContext.tsx b/frontend/src/context/UserContext.tsx
new file mode 100644
index 00000000..efc8b8a8
--- /dev/null
+++ b/frontend/src/context/UserContext.tsx
@@ -0,0 +1,31 @@
+/* eslint-disable react-refresh/only-export-components */
+import React, { ReactNode, createContext, useContext, useMemo, useState } from 'react'
+import * as movininTypes from ':movinin-types'
+
+// Create context
+export interface UserContextType {
+ user: movininTypes.User | null
+ setUser: React.Dispatch>
+ userLoaded: boolean
+ setUserLoaded: React.Dispatch>
+}
+
+const UserContext = createContext(null)
+
+// Create a provider
+interface UserProviderProps {
+ children: ReactNode
+}
+
+export const UserProvider: React.FC = ({ children }) => {
+ const [user, setUser] = useState(null)
+ const [userLoaded, setUserLoaded] = useState(false)
+ const value = useMemo(() => ({ user, setUser, userLoaded, setUserLoaded }), [user, userLoaded])
+
+ return (
+ {children}
+ )
+}
+
+// Create a custom hook to access context
+export const useUserContext = () => useContext(UserContext)
diff --git a/frontend/src/pages/Settings.tsx b/frontend/src/pages/Settings.tsx
index 93d64d9e..151a8cf7 100644
--- a/frontend/src/pages/Settings.tsx
+++ b/frontend/src/pages/Settings.tsx
@@ -23,13 +23,14 @@ import Backdrop from '@/components/SimpleBackdrop'
import DatePicker from '@/components/DatePicker'
import Avatar from '@/components/Avatar'
import * as helper from '@/common/helper'
+import { useUserContext, UserContextType } from '@/context/UserContext'
import '@/assets/css/settings.css'
const Settings = () => {
const navigate = useNavigate()
- const [user, setUser] = useState()
+ const { user, setUser } = useUserContext() as UserContextType
const [fullName, setFullName] = useState('')
const [phone, setPhone] = useState('')
const [location, setLocation] = useState('')
@@ -176,7 +177,7 @@ const Settings = () => {
}
return (
-
+
{visible && user && (
diff --git a/frontend/src/pages/SignIn.tsx b/frontend/src/pages/SignIn.tsx
index a94674d9..4c5b1e5a 100644
--- a/frontend/src/pages/SignIn.tsx
+++ b/frontend/src/pages/SignIn.tsx
@@ -12,6 +12,7 @@ import * as movininTypes from ':movinin-types'
import { strings as commonStrings } from '@/lang/common'
import { strings } from '@/lang/sign-in'
import * as UserService from '@/services/UserService'
+import { useUserContext, UserContextType } from '@/context/UserContext'
import Error from '@/components/Error'
import Layout from '@/components/Layout'
import SocialLogin from '@/components/SocialLogin'
@@ -20,6 +21,8 @@ import '@/assets/css/signin.css'
const SignIn = () => {
const navigate = useNavigate()
+
+ const { setUser, setUserLoaded } = useUserContext() as UserContextType
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState(false)
@@ -53,6 +56,10 @@ const SignIn = () => {
} else {
setError(false)
+ const user = await UserService.getUser(res.data._id)
+ setUser(user)
+ setUserLoaded(true)
+
const params = new URLSearchParams(window.location.search)
if (params.has('from')) {
const from = params.get('from')