@@ -11,7 +11,8 @@ interface AuthContextType {
11
11
login : ( email : string , password : string ) => Promise < void > ;
12
12
logout : ( ) => Promise < void > ;
13
13
register : ( email : string , password : string , username : string ) => Promise < void > ;
14
- updateUser : ( userUpdateInput : IUserUpdateInput ) => Promise < void > ;
14
+ updateUser : ( userId : string , userUpdateInput : IUserUpdateInput ) => Promise < User > ;
15
+ deactivateUser : ( userId : string ) => Promise < void > ;
15
16
}
16
17
17
18
const AuthContext = createContext < AuthContextType | undefined > ( undefined ) ;
@@ -70,11 +71,19 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
70
71
handleSuccessfulAuth ( accessToken , user ) ;
71
72
} ;
72
73
73
- const updateUser = async ( userUpdateInput : IUserUpdateInput ) => {
74
- if ( user ) {
75
- const updatedUser = await userUseCases . updateUser ( user ?. _id , userUpdateInput ) ;
74
+ const updateUser = async ( userId : string , userUpdateInput : IUserUpdateInput ) => {
75
+ const updatedUser = await userUseCases . updateUser ( userId , userUpdateInput ) ;
76
+ if ( userId === user ?. _id ) {
76
77
setUser ( updatedUser ) ;
77
78
}
79
+ return updatedUser ;
80
+ } ;
81
+
82
+ const deactivateUser = async ( userId : string ) => {
83
+ await userUseCases . deleteUser ( userId ) ;
84
+ if ( userId === user ?. _id ) {
85
+ logout ( ) ;
86
+ }
78
87
} ;
79
88
80
89
const handleSuccessfulAuth = ( accessToken : string , user : User ) => {
@@ -87,7 +96,9 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
87
96
const isUserAdmin = true ;
88
97
89
98
return (
90
- < AuthContext . Provider value = { { user, isLoggedIn, isUserAdmin, login, logout, register, updateUser } } >
99
+ < AuthContext . Provider
100
+ value = { { user, isLoggedIn, isUserAdmin, login, logout, register, updateUser, deactivateUser } }
101
+ >
91
102
{ children }
92
103
</ AuthContext . Provider >
93
104
) ;
0 commit comments