-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace fake API requests with B/E starter APIs #7
base: dev
Are you sure you want to change the base?
Conversation
ZAFIRKHAN824
commented
Feb 13, 2025
- Replace all fake APIs with real ones, except for the logout API, as it is not available in Swagger.
- Keep the profile API unchanged, as it was implemented in the feature-5/push-notification branch for push notification work
accessToken: email.toLowerCase(), | ||
refreshToken: "refreshToken", | ||
})) as Promise<{ accessToken: string; refreshToken: string }>; | ||
async function login({ email, password }: { email: string; password: string }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of defining multiple arguments here just make the type Login={email:string; password:string;}
and use here as payload:Login
refreshToken: "refreshToken", | ||
})) as Promise<{ accessToken: string; refreshToken: string }>; | ||
async function login({ email, password }: { email: string; password: string }) { | ||
return axios.post("auth/login", { email: email, password: password }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as this is an async function so its response will be a promise , so you should use await here.
} | ||
|
||
const changePassword = async (password: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here , make separate types for respective function arguments to avoid typo errors and increace reusability.
} | ||
|
||
const changePassword = async (password: string) => { | ||
const res = await axios.post<string>("auth/changePassword", password, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to type casting here await axios.post<string>
}; | ||
const forgotPassword = async (email: string) => { | ||
const res = await axios.post("/auth/forgotPassword", email, { | ||
headers: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we need to define the content type here ? as we know that the json body wiil receive at backend
|
||
const resetPassword = async (data: ForgotPassword) => { | ||
const res = await axios.post("/auth/resetPassword", data, { | ||
headers: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here as above,
"Content-Type": "application/json", | ||
}, | ||
}); | ||
return res.data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't wan to transform the response from the api then return directly that response instead of holding it in a res variable just return like return await axiox.post('auth/resetPassword',data)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i more thig i have notice here that there is a mismatch in writing function syntax . either use an array function approach or use regular function
localStorage.removeItem("accessToken"); | ||
localStorage.removeItem("refreshToken"); | ||
}); | ||
const changePassword = createAsyncThunk( | ||
`${name}/changePassword`, | ||
async (password: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we don't want to hold the response for any othere use than we simply do this createAsyncThunk(
${name}/changePassword,authService.changePassword
); | ||
const forgotPassword = createAsyncThunk( | ||
`${name}/forgotPassword`, | ||
async (email: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly here also
); | ||
const resetPassword = createAsyncThunk( | ||
`${name}/resetPassword`, | ||
async (data: ForgotPassword) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly here also
@ZAFIRKHAN824 kindly make habbit to resolve the comments after changes done |
export type ForgotPassword = { | ||
email: string; | ||
}; | ||
export type Password = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i suggest its name be like changedPassword
|
||
async function login({ email, password }: { email: string; password: string }) { | ||
return axios.post("auth/login", { email: email, password: password }); | ||
async function login(data: Login) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please , follow single format as i have mentioned previously here still i have seen some regular function and some arrow functions