Skip to content

Commit 51498e6

Browse files
committed
login/logout and demouser buttons working as well as the welcome on dashboard page.
1 parent c63eee5 commit 51498e6

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed
Binary file not shown.

backend/app/api/routes/auth.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,22 @@ def refresh():
147147
@jwt_required()
148148
def get_me():
149149
"""Get current user info."""
150-
current_user_id = get_jwt_identity()
151-
token = get_jwt()
150+
try:
151+
current_user_id = get_jwt_identity()
152+
token = get_jwt()
152153

153-
# Verify token type
154-
if token.get('type') != 'access':
155-
raise AuthenticationError('Invalid token type')
154+
# Verify token type
155+
if token.get('type') != 'access':
156+
raise AuthenticationError('Invalid token type')
156157

157-
with get_db() as db:
158-
user = User.get_by_id(db, current_user_id)
159-
if not user:
160-
raise AuthenticationError('User not found')
161-
return jsonify(user.to_dict())
158+
with get_db() as db:
159+
user = db.query(User).filter(User.id == current_user_id).first()
160+
if not user:
161+
raise AuthenticationError('User not found')
162+
return jsonify(user.to_dict())
163+
except Exception as e:
164+
logger.error(f"Error fetching user info: {str(e)}", exc_info=True)
165+
raise AuthenticationError(f'Failed to fetch user info: {str(e)}')
162166

163167
@auth_bp.route('/me', methods=['PUT'])
164168
@jwt_required()
226 Bytes
Binary file not shown.

backend/app/models/user.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class User(BaseModel):
3636
physics_objects = relationship('PhysicsObject', back_populates='user', cascade='all, delete-orphan')
3737
ai_models = relationship('AIModel', back_populates='user', cascade='all, delete-orphan')
3838

39+
@classmethod
40+
def get_by_id(cls, db, user_id):
41+
"""Get user by ID."""
42+
return db.query(cls).filter(cls.id == user_id).first()
43+
3944
def set_password(self, password):
4045
"""Set password hash."""
4146
self.password_hash = get_password_hash(password)
@@ -75,6 +80,7 @@ def to_dict(self):
7580
"""Convert user instance to dictionary."""
7681
base_dict = super().to_dict()
7782
user_dict = {
83+
'username': self.username,
7884
'email': self.email,
7985
'is_active': self.is_active,
8086
'is_verified': self.is_verified,

frontend/src/components/features/auth/Login.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
loginSuccess,
88
} from '../../../store/slices/authSlice';
99
import { openModal } from '../../../store/slices/modalSlice';
10-
import { api } from '../../../utils/api';
10+
import { api, endpoints } from '../../../utils/api';
1111
import { validateEmail, validatePassword } from '../../../utils/validation';
1212
import Button from '../../common/Button';
1313
import Input from '../../common/Input';

frontend/src/components/features/dashboard/Dashboard.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function Dashboard() {
2525
loading: authLoading,
2626
} = useSelector(state => state.auth);
2727

28-
console.log('user', user);
2928

3029
useEffect(() => {
3130
console.debug('Dashboard mounted, checking auth state');

frontend/src/components/features/home/Home.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
loginSuccess,
99
} from '../../../store/slices/authSlice';
1010
import { openModal } from '../../../store/slices/modalSlice';
11-
import { api } from '../../../utils/api';
11+
import { api, endpoints } from '../../../utils/api';
1212
import Button from '../../common/Button';
1313
import './Home.css';
1414

0 commit comments

Comments
 (0)