Skip to content
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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

ZAFIRKHAN824
Copy link

  1. Replace all fake APIs with real ones, except for the logout API, as it is not available in Swagger.
  2. Keep the profile API unchanged, as it was implemented in the feature-5/push-notification branch for push notification work

@MuhammadUsama-hub MuhammadUsama-hub self-requested a review February 15, 2025 06:09
accessToken: email.toLowerCase(),
refreshToken: "refreshToken",
})) as Promise<{ accessToken: string; refreshToken: string }>;
async function login({ email, password }: { email: string; password: string }) {

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 });

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) => {

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, {

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: {

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: {

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;

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)

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) => {

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) => {

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) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly here also

@MuhammadUsama-hub
Copy link

@ZAFIRKHAN824 kindly make habbit to resolve the comments after changes done

export type ForgotPassword = {
email: string;
};
export type Password = {

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) {

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants