Skip to content

Commit

Permalink
login/logout and demouser buttons working as well as the welcome on d…
Browse files Browse the repository at this point in the history
…ashboard page.
  • Loading branch information
JeyHightower committed Feb 24, 2025
1 parent c63eee5 commit 51498e6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
Binary file modified backend/app/api/routes/__pycache__/auth.cpython-39.pyc
Binary file not shown.
24 changes: 14 additions & 10 deletions backend/app/api/routes/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,22 @@ def refresh():
@jwt_required()
def get_me():
"""Get current user info."""
current_user_id = get_jwt_identity()
token = get_jwt()
try:
current_user_id = get_jwt_identity()
token = get_jwt()

# Verify token type
if token.get('type') != 'access':
raise AuthenticationError('Invalid token type')
# Verify token type
if token.get('type') != 'access':
raise AuthenticationError('Invalid token type')

with get_db() as db:
user = User.get_by_id(db, current_user_id)
if not user:
raise AuthenticationError('User not found')
return jsonify(user.to_dict())
with get_db() as db:
user = db.query(User).filter(User.id == current_user_id).first()
if not user:
raise AuthenticationError('User not found')
return jsonify(user.to_dict())
except Exception as e:
logger.error(f"Error fetching user info: {str(e)}", exc_info=True)
raise AuthenticationError(f'Failed to fetch user info: {str(e)}')

@auth_bp.route('/me', methods=['PUT'])
@jwt_required()
Expand Down
Binary file modified backend/app/models/__pycache__/user.cpython-39.pyc
Binary file not shown.
6 changes: 6 additions & 0 deletions backend/app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class User(BaseModel):
physics_objects = relationship('PhysicsObject', back_populates='user', cascade='all, delete-orphan')
ai_models = relationship('AIModel', back_populates='user', cascade='all, delete-orphan')

@classmethod
def get_by_id(cls, db, user_id):
"""Get user by ID."""
return db.query(cls).filter(cls.id == user_id).first()

def set_password(self, password):
"""Set password hash."""
self.password_hash = get_password_hash(password)
Expand Down Expand Up @@ -75,6 +80,7 @@ def to_dict(self):
"""Convert user instance to dictionary."""
base_dict = super().to_dict()
user_dict = {
'username': self.username,
'email': self.email,
'is_active': self.is_active,
'is_verified': self.is_verified,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/features/auth/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
loginSuccess,
} from '../../../store/slices/authSlice';
import { openModal } from '../../../store/slices/modalSlice';
import { api } from '../../../utils/api';
import { api, endpoints } from '../../../utils/api';
import { validateEmail, validatePassword } from '../../../utils/validation';
import Button from '../../common/Button';
import Input from '../../common/Input';
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/features/dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function Dashboard() {
loading: authLoading,
} = useSelector(state => state.auth);

console.log('user', user);

useEffect(() => {
console.debug('Dashboard mounted, checking auth state');
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/features/home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
loginSuccess,
} from '../../../store/slices/authSlice';
import { openModal } from '../../../store/slices/modalSlice';
import { api } from '../../../utils/api';
import { api, endpoints } from '../../../utils/api';
import Button from '../../common/Button';
import './Home.css';

Expand Down

0 comments on commit 51498e6

Please sign in to comment.