Skip to content
Snippets Groups Projects
Commit f20cd49a authored by Shrey Patel's avatar Shrey Patel
Browse files

fully fixed auth

parent e243302c
No related branches found
No related tags found
No related merge requests found
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import Axios from "axios"; import Axios from "axios";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import './AccountInformation.css'; // Import your external CSS file import "./AccountInformation.css"; // Import your external CSS file
const AccountInformation = ({ token }) => { const AccountInformation = ({ token }) => {
const [userInfo, setUserInfo] = useState({ const [userInfo, setUserInfo] = useState({
...@@ -21,10 +21,10 @@ const AccountInformation = ({ token }) => { ...@@ -21,10 +21,10 @@ const AccountInformation = ({ token }) => {
const getUserInfo = async () => { const getUserInfo = async () => {
try { try {
const response = await Axios.post( console.log(token);
"http://localhost:8080/user/user", const response = await Axios.post("http://localhost:8080/user/user", {
{ jwt: token.jwt } jwt: token.jwt,
); });
setUserInfo(response.data); setUserInfo(response.data);
} catch (error) { } catch (error) {
console.error("Error fetching user information:", error); console.error("Error fetching user information:", error);
...@@ -33,17 +33,14 @@ const AccountInformation = ({ token }) => { ...@@ -33,17 +33,14 @@ const AccountInformation = ({ token }) => {
const handleUpdate = async () => { const handleUpdate = async () => {
try { try {
const response = await Axios.put( const response = await Axios.put("http://localhost:8080/user/update", {
"http://localhost:8080/user/update", fname: userInfo.fname,
{ lname: userInfo.lname,
fname: userInfo.fname, password: userInfo.password,
lname: userInfo.lname, phoneNumber: userInfo.phoneNumber,
password: userInfo.password, email: userInfo.email,
phoneNumber: userInfo.phoneNumber, jwt: token.jwt,
email: userInfo.email, });
jwt: token.jwt,
}
);
setUserInfo(response.data); setUserInfo(response.data);
setUpdateSuccess(true); setUpdateSuccess(true);
console.log("User information updated successfully"); console.log("User information updated successfully");
...@@ -63,7 +60,9 @@ const AccountInformation = ({ token }) => { ...@@ -63,7 +60,9 @@ const AccountInformation = ({ token }) => {
return ( return (
<div className="account-info-container"> <div className="account-info-container">
<h2>Account Information</h2> <h2>Account Information</h2>
{updateSuccess && <p className="success-message">Information updated successfully!</p>} {updateSuccess && (
<p className="success-message">Information updated successfully!</p>
)}
<div className="info-form"> <div className="info-form">
<label htmlFor="fname">First Name</label> <label htmlFor="fname">First Name</label>
<input <input
......
...@@ -74,6 +74,7 @@ public class MainController { ...@@ -74,6 +74,7 @@ public class MainController {
found.setEmail("failed"); found.setEmail("failed");
return found; return found;
} }
System.out.println(res.get("user"));
Optional<User> usr = userRepository.findById(res.get("user")); Optional<User> usr = userRepository.findById(res.get("user"));
if (!usr.isPresent()) if (!usr.isPresent())
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment