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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions src/modules/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import axios from "@/lib/axios.config";
import { fakeApi } from "@/lib/utils/misc.utils";
import { ForgotPassword } from "../types/auth.type";
import {
ForgotPassword,
Login,
Password,
ResetPassword,
} from "../types/auth.type";

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

return await axios.post("auth/login", data);
}

async function logout() {
Expand All @@ -27,30 +32,15 @@ async function refreshToken() {
};
}

const changePassword = async (password: string) => {
const res = await axios.post<string>("auth/changePassword", password, {
headers: {
"Content-Type": "application/json",
},
});
return res.data;
const changePassword = async (data: Password) => {
return await axios.post("auth/changePassword", data);
};
const forgotPassword = async (email: string) => {
const res = await axios.post("/auth/forgotPassword", email, {
headers: {
"Content-Type": "application/json",
},
});
return res.data;
const forgotPassword = async (data: ForgotPassword) => {
return await axios.post("/auth/forgotPassword", data);
};

const resetPassword = async (data: ForgotPassword) => {
const res = await axios.post("/auth/resetPassword", data, {
headers: {
"Content-Type": "application/json",
},
});
return res.data;
const resetPassword = async (data: ResetPassword) => {
return await axios.post("/auth/resetPassword", data);
};

const authService = {
Expand Down
13 changes: 3 additions & 10 deletions src/modules/auth/slices/auth.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { RouterConfig } from "@/lib/router/router-config";
import { ThunkStatus } from "@/lib/types/misc";
import { createAsyncThunk, createSlice, PayloadAction } from "@reduxjs/toolkit";
import authService from "../services/auth.service";
import { ForgotPassword } from "../types/auth.type";

export const name = "auth";

Expand Down Expand Up @@ -42,21 +41,15 @@ const logout = createAsyncThunk(`${name}/logout`, async () => {
});
const changePassword = createAsyncThunk(
`${name}/changePassword`,
async (password: string) => {
return await authService.changePassword(password);
}
authService.changePassword
);
const forgotPassword = createAsyncThunk(
`${name}/forgotPassword`,
async (email: string) => {
return await authService.forgotPassword(email);
}
authService.forgotPassword
);
const resetPassword = createAsyncThunk(
`${name}/resetPassword`,
async (data: ForgotPassword) => {
return await authService.resetPassword(data);
}
authService.resetPassword
);

//slice
Expand Down
12 changes: 11 additions & 1 deletion src/modules/auth/types/auth.type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
export type ForgotPassword = {
export type ResetPassword = {
email: string;
otp: string;
password: string;
};
export type Login = {
email: string;
password: string;
};
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

password: string;
};