suhail commited on
Commit
706bb54
·
1 Parent(s): 0ff84fe
Files changed (1) hide show
  1. src/core/security.py +10 -23
src/core/security.py CHANGED
@@ -119,7 +119,7 @@ from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
119
  from src.core.config import settings
120
 
121
  # =========================
122
- # Password hashing (bcrypt-safe)
123
  # =========================
124
 
125
  pwd_context = CryptContext(
@@ -149,7 +149,7 @@ def hash_password(password: str) -> str:
149
  def verify_password(plain_password: str, hashed_password: str) -> bool:
150
  """
151
  Verify password safely.
152
- Never throws bcrypt length errors.
153
  """
154
  try:
155
  return pwd_context.verify(
@@ -222,27 +222,14 @@ def get_current_user(
222
  """
223
  token = credentials.credentials
224
 
225
- try:
226
- payload = verify_jwt_token(token, settings.BETTER_AUTH_SECRET)
227
 
228
- user_id = int(payload.get("sub"))
 
 
 
 
 
229
 
230
- return {
231
- "id": user_id,
232
- "email": payload.get("email"),
233
- "iat": payload.get("iat"),
234
- "exp": payload.get("exp"),
235
- }
236
 
237
- except ValueError:
238
- raise HTTPException(
239
- status_code=status.HTTP_401_UNAUTHORIZED,
240
- detail="Invalid user ID in token",
241
- headers={"WWW-Authenticate": "Bearer"},
242
- )
243
- except Exception as e:
244
- raise HTTPException(
245
- status_code=status.HTTP_401_UNAUTHORIZED,
246
- detail=f"Authentication failed: {str(e)}",
247
- headers={"WWW-Authenticate": "Bearer"},
248
- )
 
119
  from src.core.config import settings
120
 
121
  # =========================
122
+ # Password hashing (bcrypt-safe ONLY)
123
  # =========================
124
 
125
  pwd_context = CryptContext(
 
149
  def verify_password(plain_password: str, hashed_password: str) -> bool:
150
  """
151
  Verify password safely.
152
+ NEVER crashes.
153
  """
154
  try:
155
  return pwd_context.verify(
 
222
  """
223
  token = credentials.credentials
224
 
225
+ payload = verify_jwt_token(token, settings.BETTER_AUTH_SECRET)
 
226
 
227
+ return {
228
+ "id": int(payload["sub"]),
229
+ "email": payload.get("email"),
230
+ "iat": payload.get("iat"),
231
+ "exp": payload.get("exp"),
232
+ }
233
 
 
 
 
 
 
 
234
 
235
+