Skip to content

Commit

Permalink
server changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ansh101112 committed Jun 22, 2024
1 parent e8fbb82 commit 104d5d7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,25 @@ const Login = () => {
if (Object.keys(newErrors).length === 0) {
setLoading(true);
try {
const response = await axios.post("https://smartserver-production.up.railway.app/login", {
email,
password,
});
const response = await axios.post(
"https://smartserver-scbe.onrender.com/login",
{
email,
password,
}
);

if (response && response.data.success) {
localStorage.setItem("isLoggedIn", "true");
localStorage.setItem("token", response.data.token);

// Decode the token to get the user role


const tokenPayload = JSON.parse(
atob(response.data.token.split(".")[1])
);
const userRole = tokenPayload.role;


// Store user role in localStorage
localStorage.setItem(
"currentUser",
Expand Down Expand Up @@ -87,7 +88,6 @@ const Login = () => {
navigate("/");
}
}, 2000);

}
} catch (error) {
if (error.response) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const NotificationSettings = () => {
try {
const token = localStorage.getItem("token");
const response = await fetch(
"https://smartserver-production.up.railway.app/update-notification",
"https://smartserver-scbe.onrender.com/update-notification",
{
method: "PUT",
headers: {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/QR.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ const QRCodeVerification = () => {
setIsScannerOpen(false);
try {
const response = await axios.post(
`http://localhost:6352/scan-product`,
`https://smartserver-scbe.onrender.com/scan-product`,
{ barcode: data }
);
setProductInfo(response.data.product);
// Save the product information to the database if not already present
await axios.post(
`http://localhost:6352/add-product`,
`https://smartserver-scbe.onrender.com/add-product`,
response.data.product
);
} catch (err) {
Expand Down
13 changes: 8 additions & 5 deletions src/pages/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ const Settings = () => {
"Are you sure you want to delete your account permanently?"
);
if (confirmation) {
const response = await axios.delete("https://smartserver-production.up.railway.app/delete", {
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
});
const response = await axios.delete(
"https://smartserver-scbe.onrender.com/delete",
{
headers: {
Authorization: `Bearer ${localStorage.getItem("token")}`,
},
}
);

if (response.status === 200) {
setTimeout(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const SignUp = () => {
setLoading(true);
try {
const response = await axios.post(
"https://smartserver-production.up.railway.app/signup",
"https://smartserver-scbe.onrender.com/signup",
{
name: username,
email,
Expand Down
2 changes: 1 addition & 1 deletion src/settings/AccountSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const AccountSettings = () => {
try {
const token = localStorage.getItem("token");
const response = await axios.put(
"https://smartserver-production.up.railway.app/settings/account",
"https://smartserver-scbe.onrender.com/settings/account",
{
email,
password,
Expand Down

0 comments on commit 104d5d7

Please sign in to comment.