Skip to content

Commit 853a307

Browse files
committed
adding important features
1 parent db2a3d1 commit 853a307

File tree

9 files changed

+67
-1816
lines changed

9 files changed

+67
-1816
lines changed

backend/package-lock.json

Lines changed: 16 additions & 1804 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
"mongoose": "^8.18.0",
2323
"multer": "^1.4.4",
2424
"multer-gridfs-storage": "^5.0.2",
25-
"multer-s3": "^3.0.1",
25+
"multer-s3": "^2.10.0",
2626
"nodemon": "^3.1.10",
27-
"pdfkit": "^0.17.2"
27+
"pdfkit": "^0.17.2",
28+
"uuid": "^13.0.0"
2829
}
2930
}

backend/src/controllers/photo.controller.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { s3 } from '../middlewares/s3.upload.middleware.js';
2-
import User from '../models/user.model.js';
32

43
export const uploadProfilePhoto = async (req, res) => {
54
try {

backend/src/middlewares/s3.upload.middleware.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import AWS from 'aws-sdk';
2-
import multe from 'multer';
2+
import multer from 'multer';
33
import multerS3 from 'multer-s3';
44
import { v4 as uuidv4 } from 'uuid';
5+
import dotenv from 'dotenv';
6+
dotenv.config();
57

68
AWS.config.update({
79
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
@@ -28,7 +30,7 @@ const uploadPhoto = multer({
2830
}
2931
}),
3032
limits: {
31-
fileSize: 5 * 1024 * 1024 // 5MB limit
33+
fileSize: 5 * 1024 * 1024
3234
},
3335
fileFilter: (req, file, cb) => {
3436
if (file.mimetype.startsWith('image/')) {

backend/src/routes/photo.routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Router } from 'express';
22
import { uploadProfilePhoto, deleteProfilePhoto } from '../controllers/photo.controller.js';
33
import { verifyJWT } from '../middlewares/auth.middleware.js';
4-
import { uploadPhoto } from '../middlewares/s3Upload.middleware.js';
4+
import { uploadPhoto } from '../middlewares/s3.upload.middleware.js';
55

66
const router = Router();
77

frontend/src/components/AuthManager/AuthManager.jsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,45 @@ const AuthManager = () => {
1111
const [loading, setLoading] = useState(true);
1212

1313
useEffect(() => {
14-
checkAuthStatus();
14+
initializeAuth();
1515
}, []);
1616

17-
const checkAuthStatus = async () => {
17+
const initializeAuth = async () => {
1818
try {
19+
const wasLoggedOut = localStorage.getItem('wasLoggedOut') === 'true';
20+
21+
if (wasLoggedOut) {
22+
setLoading(false);
23+
return;
24+
}
25+
26+
const storedUser = localStorage.getItem('user');
27+
28+
if (!storedUser) {
29+
setLoading(false);
30+
return;
31+
}
32+
33+
const userData = JSON.parse(storedUser);
34+
setUser(userData);
35+
setIsAuthenticated(true);
36+
37+
// Verify token is still valid
1938
const response = await api.get('/users/current-user', { withCredentials: true });
39+
2040
if (response.data.success) {
21-
setUser(response.data.data);
41+
const freshUserData = response.data.data;
42+
setUser(freshUserData);
2243
setIsAuthenticated(true);
44+
localStorage.setItem('user', JSON.stringify(freshUserData));
45+
localStorage.removeItem('wasLoggedOut');
46+
} else {
47+
throw new Error('Token invalid');
2348
}
2449
} catch (error) {
50+
// Clear invalid data
51+
localStorage.removeItem('user');
52+
localStorage.removeItem('wasLoggedOut');
2553
setIsAuthenticated(false);
2654
setUser(null);
2755
} finally {
@@ -30,15 +58,20 @@ const AuthManager = () => {
3058
};
3159

3260
const handleLogin = (userData) => {
33-
setUser(userData);
61+
const actualUser = userData.user || userData;
62+
setUser(actualUser);
3463
setIsAuthenticated(true);
3564
setShowRegister(false);
65+
localStorage.setItem('user', JSON.stringify(userData));
66+
localStorage.removeItem('wasLoggedOut');
3667
};
3768

3869
const handleRegister = (userData) => {
3970
setUser(userData);
4071
setIsAuthenticated(true);
4172
setShowRegister(false);
73+
localStorage.setItem('user', JSON.stringify(userData));
74+
localStorage.removeItem('wasLoggedOut');
4275
};
4376

4477
const handleLogout = async () => {
@@ -47,6 +80,8 @@ const AuthManager = () => {
4780
} catch (error) {
4881
console.error('Logout error:', error);
4982
} finally {
83+
localStorage.setItem('wasLoggedOut', 'true');
84+
localStorage.removeItem('user');
5085
setUser(null);
5186
setIsAuthenticated(false);
5287
}

frontend/src/components/Dashboard/CVBuilder/steps/BasicDetailsStep.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useState } from 'react';
22
import FormField from '../forms/FormField';
33
import FormGrid from '../forms/FormGrid';
44
import { Upload, X, User, Plus, Trash2, AlertCircle } from 'lucide-react';
5+
import { toast } from 'react-toastify';
6+
import api from '../../../../utils/api';
57
import {
68
GENDER_OPTIONS,
79
LANGUAGE_OPTIONS,
@@ -19,6 +21,7 @@ const BasicDetailsStep = ({ formData, onInputChange }) => {
1921
const [photoPreview, setPhotoPreview] = useState(null);
2022
const [errors, setErrors] = useState({});
2123
const [touched, setTouched] = useState({});
24+
const [uploading, setUploading] = useState(false);
2225

2326
const languages = formData.basicDetails.languages || [];
2427

frontend/src/components/Dashboard/Dashboard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const DashboardLayout = ({ user, onLogout }) => {
88
const [activeSection, setActiveSection] = useState('cv-builder');
99
const [currentCVStep, setCurrentCVStep] = useState(1);
1010
const [completedSteps, setCompletedSteps] = useState([]);
11-
11+
console.log('DashboardLayout user prop:', user);
1212
const handleSectionChange = (section) => {
1313
setActiveSection(section);
1414
if (section === 'cv-builder' && activeSection !== 'cv-builder') {

frontend/src/components/Dashboard/Sidebar.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const Sidebar = ({
1515
const [showPrograms, setShowPrograms] = useState(
1616
['systematic-reviews', 'case-reports', 'conferences', 'workshops', 'emr-training'].includes(activeSection)
1717
);
18-
1918
const mainNavigationItems = [
2019
{ id: 'cv-builder', label: 'CV Builder', icon: FileText },
2120
{ id: 'cv-status', label: 'View CV', icon: Eye },

0 commit comments

Comments
 (0)