-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refcator : added helper methods for updating profile
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"use server"; | ||
|
||
import updateAddress from "./update-address"; | ||
import updatePersonal from "./update-personal"; | ||
import updateSecurity from "./update-security"; | ||
|
||
export { updateAddress, updatePersonal, updateSecurity }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import getBaseUrl from "@utils/getBaseUrl"; | ||
import { getSessionToken } from "../sessions/sessionUtils"; | ||
|
||
export default async function updateAddress(filteredFields: any) { | ||
const session = getSessionToken(); | ||
const serverUrl = getBaseUrl(); | ||
|
||
const headers = { | ||
Authorization: `Bearer ${session}`, | ||
}; | ||
|
||
try { | ||
const response = await fetch(`${serverUrl}/api/update-profile/address`, { | ||
method: "PUT", | ||
headers, | ||
body: JSON.stringify(filteredFields), | ||
}); | ||
|
||
const success = await response.json(); | ||
|
||
return success; | ||
} catch (error) { | ||
console.error("Error updating address information:", error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import getBaseUrl from "@utils/getBaseUrl"; | ||
import { getSessionToken } from "../sessions/sessionUtils"; | ||
|
||
export default async function updatePersonal(filteredFields: any) { | ||
const session = getSessionToken(); | ||
const serverUrl = getBaseUrl(); | ||
|
||
const headers = { | ||
Authorization: `Bearer ${session}`, | ||
}; | ||
|
||
try { | ||
const response = await fetch(`${serverUrl}/api/update-profile/personal`, { | ||
method: "PUT", | ||
headers, | ||
body: JSON.stringify(filteredFields), | ||
}); | ||
|
||
const success = await response.json(); | ||
|
||
return success; | ||
} catch (error) { | ||
console.error("Error updating personal information:", error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import getBaseUrl from "@utils/getBaseUrl"; | ||
import { getSessionToken } from "../sessions/sessionUtils"; | ||
|
||
export default async function updateSecurity(password: string) { | ||
const session = getSessionToken(); | ||
const serverUrl = getBaseUrl(); | ||
|
||
const headers = { | ||
Authorization: `Bearer ${session}`, | ||
}; | ||
|
||
try { | ||
const response = await fetch( | ||
`${serverUrl}/api/update-profile/reset-password`, | ||
{ | ||
method: "PUT", | ||
headers, | ||
body: JSON.stringify({ password }), | ||
} | ||
); | ||
|
||
const success = await response.json(); | ||
|
||
return success; | ||
} catch (error) { | ||
console.error("Error updating password :", error); | ||
} | ||
} |