Skip to content

Commit

Permalink
Refactor: the generate forgot password link to be a post request.
Browse files Browse the repository at this point in the history
Also after sending login and signup requests, make the payload to be null, so it's not saved in the heap
  • Loading branch information
georgipavlov-7DIGIT committed Feb 7, 2024
1 parent 207b8b6 commit d5e3cc7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/blocks/ForgotPassword/ForgotPassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const ForgotPassword = ({ navigation }) => {
const [data, setData] = useState({ email: "" });
const [errors, setErrors] = useState({});
const [isModalOpen, setIsModalOpen] = useState(false);
const [loading, setLoading] = useState(false);

const schema = Joi.object({
email: Joi.string()
Expand All @@ -32,6 +33,7 @@ export const ForgotPassword = ({ navigation }) => {
});

const handleResetPassword = async () => {
setLoading(true);
if ((await validate(data, schema, setErrors)) == null) {
try {
await userSvc.generateForgotPasswordLink(
Expand All @@ -44,6 +46,7 @@ export const ForgotPassword = ({ navigation }) => {
setErrors({ submit: errorMessage });
}
}
setLoading(false);
};

const canContinue = data.email === "";
Expand All @@ -58,6 +61,7 @@ export const ForgotPassword = ({ navigation }) => {
<Input
label={t("input_email_label")}
value={data.email}
autoCapitalize="none"
placeholder={"[email protected]"}
onChange={(value) => setData({ email: value })}
errorMessage={errors.email}
Expand All @@ -69,6 +73,7 @@ export const ForgotPassword = ({ navigation }) => {
size="lg"
onPress={handleResetPassword}
disabled={canContinue}
loading={loading}
style={styles.button}
/>
</View>
Expand Down
30 changes: 24 additions & 6 deletions src/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async function signUp({
clientData = {},
providerData = {},
}) {
const data = {
let data = {
userType,
countryID,
password,
Expand All @@ -50,6 +50,13 @@ async function signUp({
}

const response = await http.post(`${API_ENDPOINT}/signup`, data);

delete data.password;
delete data.userAccessToken;
delete data.email;

data = null;

return response;
}

Expand All @@ -66,7 +73,7 @@ async function refreshToken(refreshToken) {
}

async function login({ userType, email, password, userAccessToken, location }) {
const payload = { userType, password, isMobile: true };
let payload = { userType, password, isMobile: true };
if (userAccessToken) {
payload.userAccessToken = userAccessToken;
} else {
Expand All @@ -76,6 +83,13 @@ async function login({ userType, email, password, userAccessToken, location }) {
const response = await http.post(`${API_ENDPOINT}/login`, payload, {
headers,
});

delete payload.password;
delete payload.userAccessToken;
delete payload.email;

payload = null;

return response;
}

Expand Down Expand Up @@ -134,12 +148,16 @@ async function updateNotificationPreferences(data) {
/**
*
* @param {String} email -> the email of the user
* @param {*} userType -> the type of the user "client" or "provider"
* @param {String} type -> the type of the user "client" or "provider"
* @returns
*/
async function generateForgotPasswordLink(email, userType) {
const response = await http.get(
`${API_ENDPOINT}/rescue/forgot-password?email=${email.toLowerCase()}&type=${userType}`
async function generateForgotPasswordLink(email, type) {
const response = await http.post(
`${API_ENDPOINT}/rescue/forgot-password-link`,
{
email,
type,
}
);
return response;
}
Expand Down

0 comments on commit d5e3cc7

Please sign in to comment.