@@ -89,44 +89,48 @@ export const uploadAvatar = (images) => ({
8989 payload : images ,
9090} ) ;
9191
92- export const fetchRegisterUser = ( user ) => async ( dispatch ) => {
93- dispatch ( userLoading ( ) ) ;
94- try {
95- const response = await axios . post ( `${ url } /profile/register` , user ) ;
96- const data = await response . data ;
97- return [
98- dispatch ( registerUser ( data . user ) ) ,
99- dispatch ( userLoadingEnd ( ) ) ,
100- dispatch ( setToken ( data . token ) ) ,
101- localStorage . setItem ( 'token' , JSON . stringify ( data . token ) ) ,
102- localStorage . setItem ( 'user' , JSON . stringify ( data . user ) ) ,
103- dispatch ( push ( '/' ) ) ,
104- toaster . notify (
105- ( ) => (
106- < NotificationComponent
107- success = { true }
108- text = { `Welcome! Enjoy your time` }
109- />
92+ export const fetchRegisterUser =
93+ ( { name, email, password } ) =>
94+ async ( dispatch ) => {
95+ dispatch ( userLoading ( ) ) ;
96+ try {
97+ const response = await axios . post ( `${ url } /profile/register` , null , {
98+ params : { email, name, password } ,
99+ } ) ;
100+ const data = await response . data ;
101+ return [
102+ dispatch ( registerUser ( data . user ) ) ,
103+ dispatch ( userLoadingEnd ( ) ) ,
104+ dispatch ( setToken ( data . token ) ) ,
105+ localStorage . setItem ( 'token' , JSON . stringify ( data . token ) ) ,
106+ localStorage . setItem ( 'user' , JSON . stringify ( data . user ) ) ,
107+ dispatch ( push ( '/' ) ) ,
108+ toaster . notify (
109+ ( ) => (
110+ < NotificationComponent
111+ success = { true }
112+ text = { `Welcome! Enjoy your time` }
113+ />
114+ ) ,
115+ { duration : 1500 }
110116 ) ,
111- { duration : 1500 }
112- ) ,
113- ] ;
114- } catch ( error ) {
115- return [
116- dispatch ( userFetchError ( error ) ) ,
117- dispatch ( userLoadingEnd ( ) ) ,
118- toaster . notify (
119- ( ) => (
120- < NotificationComponent
121- text = { 'Oops! Something went wrong!' }
122- success = { false }
123- />
117+ ] ;
118+ } catch ( error ) {
119+ return [
120+ dispatch ( userFetchError ( error ) ) ,
121+ dispatch ( userLoadingEnd ( ) ) ,
122+ toaster . notify (
123+ ( ) => (
124+ < NotificationComponent
125+ text = { 'Oops! Something went wrong!' }
126+ success = { false }
127+ />
128+ ) ,
129+ { duration : 1500 }
124130 ) ,
125- { duration : 1500 }
126- ) ,
127- ] ;
128- }
129- } ;
131+ ] ;
132+ }
133+ } ;
130134
131135export const fetchLogoutUser = ( ) => async ( dispatch ) => {
132136 const token = JSON . parse ( localStorage . getItem ( 'token' ) ) ;
@@ -153,44 +157,48 @@ export const fetchLogoutUser = () => async (dispatch) => {
153157 }
154158} ;
155159
156- export const fetchLoginUser = ( user ) => async ( dispatch ) => {
157- dispatch ( userLoading ( ) ) ;
158- try {
159- const response = await axios . post ( `${ url } /profile/login` , user ) ;
160- const data = await response . data ;
161- return [
162- dispatch ( loginUser ( data . user ) ) ,
163- dispatch ( userLoadingEnd ( ) ) ,
164- dispatch ( setToken ( data . token ) ) ,
165- localStorage . setItem ( 'token' , JSON . stringify ( data . token ) ) ,
166- localStorage . setItem ( 'user' , JSON . stringify ( data . user ) ) ,
167- dispatch ( push ( '/home' ) ) ,
168- toaster . notify (
169- ( ) => (
170- < NotificationComponent
171- success = { true }
172- text = { `Welcome! Enjoy your time` }
173- />
160+ export const fetchLoginUser =
161+ ( { email, password } ) =>
162+ async ( dispatch ) => {
163+ dispatch ( userLoading ( ) ) ;
164+ try {
165+ const response = await axios . post ( `${ url } /profile/login` , null , {
166+ params : { email, password } ,
167+ } ) ;
168+ const data = await response . data ;
169+ return [
170+ dispatch ( loginUser ( data . user ) ) ,
171+ dispatch ( userLoadingEnd ( ) ) ,
172+ dispatch ( setToken ( data . token ) ) ,
173+ localStorage . setItem ( 'token' , JSON . stringify ( data . token ) ) ,
174+ localStorage . setItem ( 'user' , JSON . stringify ( data . user ) ) ,
175+ dispatch ( push ( '/home' ) ) ,
176+ toaster . notify (
177+ ( ) => (
178+ < NotificationComponent
179+ success = { true }
180+ text = { `Welcome! Enjoy your time` }
181+ />
182+ ) ,
183+ { duration : 1500 }
174184 ) ,
175- { duration : 1500 }
176- ) ,
177- ] ;
178- } catch ( error ) {
179- return [
180- dispatch ( userFetchError ( error ) ) ,
181- dispatch ( userLoadingEnd ( ) ) ,
182- toaster . notify (
183- ( ) => (
184- < NotificationComponent
185- text = { 'Oops! Something went wrong!' }
186- success = { false }
187- />
185+ ] ;
186+ } catch ( error ) {
187+ return [
188+ dispatch ( userFetchError ( error ) ) ,
189+ dispatch ( userLoadingEnd ( ) ) ,
190+ toaster . notify (
191+ ( ) => (
192+ < NotificationComponent
193+ text = { 'Oops! Something went wrong!' }
194+ success = { false }
195+ />
196+ ) ,
197+ { duration : 1500 }
188198 ) ,
189- { duration : 1500 }
190- ) ,
191- ] ;
192- }
193- } ;
199+ ] ;
200+ }
201+ } ;
194202
195203// To get the user,
196204// but because I added an or statement in user and token initial states,
0 commit comments